GWTReact / gwt-react

GWT Java bindings for React
MIT License
91 stars 17 forks source link

Decide how to expose React contexts #6

Open ivmarkov opened 7 years ago

ivmarkov commented 7 years ago

As the React documentation (https://facebook.github.io/react/docs/context.html) for context says:

The vast majority of applications do not need to use context.

If you want your application to be stable, don't use context. It is an experimental API and it is likely to break in future releases of React.

At the same time, the current support for contexts in GwtReact is:

we can write:

StatelessComponent<?> component = props -> ...

... which is shorter and simpler.

In my opinion, context should probably be supported, but should not be "seen" by the user when not in use. One simple way to do this is to simplify StatelessComponent as suggested here, and then in parallel introduce a StatelessComponentWithContext or suchlike, which would be the context-aware alternative of StatelessComponent, with a second "context" parameter, support for contextTypes static (somehow) and so on and so forth.

pstockley commented 7 years ago

I agree the default path for components should exclude context. In general, I stayed away from prop types. Given the typed nature of java, they are less important. Although, they can still catch some runtime bugs when you are building props on the fly.

ivmarkov commented 7 years ago

Regarding prop types - you misunderstood. Of course they are unnecessary in a typed environment like Java (or TypeScript or Flow). However, the context types (mind you: not prop types), while unnecessary as well for us are - unfortunately - required by React. See here: https://facebook.github.io/react/docs/context.html

If contextTypes is not defined, then context will be an empty object.

pstockley commented 7 years ago

I currently have no need for context support. However, I would happily take a pull request to add support

ivmarkov commented 7 years ago

Let's leave it open for now, if you don't mind. We also don't see much use for contexts right now.

pstockley commented 6 years ago

I will address this with React 16.3