From bd86c53822d614df3de37f71555b751bb3bc19f2 Mon Sep 17 00:00:00 2001 From: petehunt Date: Mon, 30 Dec 2013 13:22:06 -0500 Subject: [PATCH] Update parent/child communication tip --- tips/14-communicate-between-components.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tips/14-communicate-between-components.md b/tips/14-communicate-between-components.md index 84c1a9fe..39e79c6b 100644 --- a/tips/14-communicate-between-components.md +++ b/tips/14-communicate-between-components.md @@ -18,7 +18,7 @@ var GroceryList = React.createClass({ handleClick: function(i) { console.log('You clicked: ' + this.props.items[i]); }, - + render: function() { return (
@@ -26,7 +26,7 @@ var GroceryList = React.createClass({ return (
{item}
); - }, this)} + }, this)}
); } @@ -38,3 +38,5 @@ React.renderComponent( ``` Notice the use of `bind(this, arg1, arg2, ...)`: we're simply passing more arguments to `handleClick`. This is not a new React concept; it's just JavaScript. + +For communication between two components that don't have a parent-child relationship, you can set up your own global event system. Subscribe to events in `componentDidMount()`, unsubscribe in `componentWillUnmount()`, and when you receive an event call `setState()`.