admin管理员组文章数量:1415655
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/.
本文标签: javascriptHow to use getChildContext with functional componentsStack Overflow
版权声明:本文标题:javascript - How to use getChildContext with functional components - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745175156a2646199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论