6 ms·
You wouldn't necessarily use ReasonML instead of React, you can use them together. You would use ReasonML instead of whatever Babel/es6/es7/typescript/whatever.
by bratsche 8y ago
You wouldn't necessarily use ReasonML instead of React, you can use them together. You would use ReasonML instead of whatever Babel/es6/es7/typescript/whatever.
Here is the official React binding (or whatever you call it) for ReasonML:
https://reasonml.github.io/reason-react/ https://reasonml.github.io/reason-react/
Using this you would still be using React, just in a different language. But my understanding is that you would not be using redux (if you are now) because it doesn't make sense in a language like ReasonML.
- RussianCow 8y ago> But my understanding is that you would not be using redux (if you are now) because it doesn't make sense in a language like ReasonML. Why would using Redux not make sense? It's not like the problem of sharing state between components goes away with a functional language?
- Kiro 8y agoIt's covered in the article: "When using ReasonML, we don't need Redux anymore. ReactReason stateless components already come with the concept of a build in reducer, which is meant to take care of the problems Redux used to address."
- RussianCow 8y agoReducers are only one (and IMO the least important) part of using Redux with React; the other part is `connect`, which lets you pass global state directly into a deeply nested component without passing it all the way down the tree via props. Unless I'm mistaken, ReactReason doesn't offer an alternative to that.
- cdaringe 8y agoHistorically a single connected root has been frowned upon. I'm not so sure it should still be feared now that you can use PureComponents and FSCs the whole way down. ShouldComponentUpdate calls are cheap in pure-town.
- RussianCow 8y agoFor me, it's not a matter of performance, but rather of convenience. If I have a deeply nested component that needs to dispatch an action or access a part of the global state, I don't want to have to pass that all the way down through every other component in the hierarchy. The grandparent of a "Like" button shouldn't need to know the details of how it's implemented with regards to the global state, but it's forced to if you pass everything via props.
- DougBTX 8y agoThe newly official Context API might change things here, since it will be much easier to pass state down to grandchildren. I’ve not been keeping up to date with the plans for what react-redux will do with the new API yet, could be interesting.
- cdaringe 8y agoAction creators always felt like and unnecessary abstraction to me. To avoid the aforementioned problem, I passed down a message library, or action object that has all of the actions on it, and dispatch. It's all I need!
- acemarke 8y agoSure, action creators are "unnecessary" - you can always declare action objects and action types directly inline: this.props.dispatch({type : "INCREMENT"}); Nothing's ever _forced_ you to use action creators, or declare your type constants separately. However, we encourage use of action creators as a good practice. See my blog post "Idiomatic Redux: Why Use Action Creators?" [0] for some reasons, as well as the related Redux FAQ entry [1]. [0] http://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why-use-action-creators/ http://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why... [1] https://redux.js.org/faq/code-structure#why-should-i-use-action-creators https://redux.js.org/faq/code-structure#why-should-i-use-act...
- 8y ago
- crooked-v 8y agoThe new context API can probably help with that. Pass an object through context that contains the reducer state of a root level component (or a getState() or whatever), plus a dispatch function. Blam, Redux-equivalent without a separate library.
- RobertKerans 8y agoReasonReact doesn't have Context, the API is unstable so they aren't binding to it.
- RussianCow 8y agoThe new API as of 16.3 is stable, so I suspect ReactReason will support it soon (if it doesn't already, by default). https://reactjs.org/docs/context.html https://reactjs.org/docs/context.html
- RobertKerans 8y agoAh, that's great that it's finally settled. RR is on v15 in terms of what it has to support though, so no dice; main focus at the minute seems to be on dropping v15 support and migrating to v16, which cleans up some of the code (particularly w/r/t the async side), but that has to happen before they bind to the new API, so going to be a while.
- bratsche 8y agoI commented before reading the article, just going by memory of reading about this before. Perhaps I was wrong about it not making sense in the language, but more that it isn't necessary when using ReactReason because the concept is built into that binding.