Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think hooks are more like applicative/arrow and are not monads. This ensures the shape is static and you cannot branch based on input.

This also illustrates how weird it is to call function components pure. They’re not, there as effecful as can be!



Yeah I agree that morally the interface is applicative or arrow like but I didn’t think that provided an ergonomic programming interface which is most of the point of hooks (and the pain of arrows). Binds couldn’t really changed the shape of their output because of the second type parameter I described. Also, I don’t see a particular reason to disallow the default value of one state depending on the value of something else. You can’t really stop them from depending on eg function arguments in a nice way.


If you haven't seen the Bonsai OCaml library, they provide an arrow based interface for making web apps. I find it very straight forward to use and everything is based around composing functions. A "component" is:

  type ('a, 'b) t = 'a Value.t -> 'b Computation.t
and then there's various ways to hook them up and depend on each other.

https://github.com/janestreet/bonsai/blob/master/docs/proc.m...

Gives a bit of an overview. There are some syntax extensions to make working with it a bit easier. But once grokked it seems to fit nicely, and feels like more of a solid foundation than React (imo).

Not all the examples have been updated to the new style, but here's one (albeit trivial) example: https://github.com/janestreet/bonsai/blob/master/examples/tw...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: