I’ve recently been reading through the book Road to React in order to learn more about React.
Road to React was recently rewritten to be based on React Hooks.
I’ve translated the example from Road to React to PureScript using the purescript-react-basic-hooks library. If I was writing a larger application and not just a self-contained example, there are some things I would do differently, but I thought some people here might be interested anyway:
See the README.md in the repo for more info.
react-basic-hooks is written), but there was one thing I had some trouble with.
You can see that this component takes some props as arguments. The prop
type has a default value of
This is what I wasn’t sure how to express in PureScript.
I ended up using a type class to express a record with both optional and required values. I defined the defaults for the optional values in the function:
InputProps type class synonym is defined as so:
This isn’t the prettiest code, but it seems to work.
How do other people deal with this type of situation?