purescript-contrib / purescript-react

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

Initial hooks implementation #159

Open ethul opened 5 years ago

ethul commented 5 years ago

Proposal for supporting React Hooks.

This code is still in the early stages and requires some ideas to be worked out further, but perhaps it is a useful start for a discussion. Any comments, questions, or suggestions are most welcome.

// @natefaubion

ethul commented 5 years ago

@natefaubion Thanks for taking a look at all of this!

ethul commented 5 years ago

Example usage of hooks: https://github.com/ethul/purescript-react-example/tree/hooks

natefaubion commented 5 years ago

It's definitely worth looking at the react-basic implementation which uses indexed-monads and qualified do to make it ergonomic and type safe.

ethul commented 5 years ago

Thanks for pointing out the react-basic hooks implementation. It is a nice representation. A part of me wonders if it would make sense to have a more general hooks implementation that can be shared among purescript react libraries.

On another note, and as a point for discussion, I suppose I am a bit on the fence about tracking hooks via the index-monad, which seems along the lines of how Eff tracked effects (unless I am not understanding this correctly). I can see the how this could be handy, but I may need to mull over the pros and cons a bit more. But I am open to ideas on this.

JordanMartinez commented 3 years ago

Should this PR be closed? AFAIK, most people use react-basic now, which also has a hooks library.