purescript-contrib / purescript-react

React Bindings for PureScript
MIT License
400 stars 65 forks source link

contextType constructor property #163

Closed athanclark closed 5 years ago

athanclark commented 5 years ago

From what I understand, React 16.x supports this whole "context" paradigm, where a value can be propagated from a Provider down to child Consumers, however the component that is wrapped by a Consumer should be accepted via an explicit contextType property - here's the React docs that detail it.

Should we make this an additional field in the ReactSpecOptional row? I think it's a pretty simple non-breaking change, and an additional case statement in the top level switch in the src/React.js file would probably do the trick, but I wanted to start the discussion here before amending it.

natefaubion commented 5 years ago

contextType is a static property, while the ReactSpec fields are bound at instance construction. This field would need to be configured at class construction like componentWithDerivedState does.

natefaubion commented 5 years ago

Note, that you don't need the static property to use context. You can use createLeafElement myContext.consumer { children: \value -> ... }

athanclark commented 5 years ago

Oh, well shoot haha. So the contextType is something like propTypes or whatever? Yeah, I think it's a good idea to just leave it to the typechecker. Thank you!