Communicate Between Components Back
- parent-child: just pass props
- child-parent: use
bind(this, arguments)
var handleClick = function (i, props) {
console.log('clicked: ' + props.items[i]);
};
function List(props) {
return (
<div>
{
props.items.map(function (item, i) {
return (
<div onClick={handleClick.bind(this, i, props)} key={i}>{item}</div>
);
});
}
</div>
);
}
ReactDOM.render(
<List items={['Apple', 'Banana', 'Cranberry']} />,
document.getElementById('content')
);
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 call setState()
when you receive an event.
As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.
Notice: This plugin has used Cookie to store your token with an expiration.