[Reactjs] Reference children instance
The API this.props.children</code> is not the things when we want to reference the instance creating in render() function. The only way to reference it is adding ref property in render() function.
And, if it's dynamic, use React.cloneElement</code> to set ref.
js
render: function () {
var refPages = this.state.pages.map(function(page) {
return React.cloneElement(page, {ref: page.key, key: page.key});
}, this);
return (
<div className="pageslider-container">
{refPages}
</div>
);
}
Written by Alive.Kuo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#