I want to pass some props down the tree via context from a functional ponent
that is almost on the top of the app. Is there a way to achieve this, or should we declare instead a ES6 / createClass
react ponent?
Thanks
I want to pass some props down the tree via context from a functional ponent
that is almost on the top of the app. Is there a way to achieve this, or should we declare instead a ES6 / createClass
react ponent?
Thanks
Share Improve this question edited Sep 8, 2016 at 15:35 jsdario asked Sep 8, 2016 at 15:24 jsdariojsdario 6,87311 gold badges44 silver badges78 bronze badges2 Answers
Reset to default 6You can't pass context to children using functional ponents
Define the contextTypes as you would normally do:
const Hello = (props, context) => <div>{context.name}</div>;
Hello.contextTypes = {
name: React.PropTypes.string
};
A fiddle is available: https://jsfiddle/69z2wepo/55601/.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745175157a4615152.html
评论列表(0条)