This is slightly complex to explain here, but your code will now work on the master build of React (post 0.10.0).
I'm not too sure what you're trying to accomplish here, but if you change your this.props.passedChild
to this.props.passedChild()
and c = Child();
to c = Child;
, it'll work. Call it this.props.passedChildClass
or something. You can also try this.props.passedChildFn
with c = function() { return Child(); }
. Whatever suits your need.
Don't create an instance of a component and pass it around (it won't be a big problem anymore soon; the return value of Child()
won't be an instance anymore). In general it's bad practice because this encourages mutation. Create your children on the fly as you need them and let React handle the rest.
In my application, there is quite a bit of logic around when components are created that would make it impractical to do everything in render().
Break them into helper functions! You really don't have to stuff everything into a single render
.
Also, global state is a bad idea. The fact that your child updates correctly by reading from globalState
is very fragile. You must have gotten a warning in your console (providing you're using the dev build) to add an onChange
handler. Go read it =).