Skip to content

v0.3.0

Compare
Choose a tag to compare
@thomashoneyman thomashoneyman released this 07 May 15:58
8fd0f0b

This release changes how users update state in Hooks.

Breaking changes (😱!!!):

Replace state tokens with a modify function (#29)

The previous versions of Hooks returned a state token from the useState hook, which could then be passed to the put, modify, modify_, and get functions we're all used to from HalogenM. Now, the useState hook returns a modify function directly which can be used to update the state. See #29 for more details on why this matters.

This code from v0.2.1:

state /\ stateToken <- Hooks.useState 0
let handleClick = Hooks.modify_ stateToken (_ + 1)
Hooks.pure ...

Would now be written like this:

state /\ modifyState <- Hooks.useState 0
let handleClick = modifyState (_ + 1)
Hooks.pure ...

Now that there isn't a get function, if you need to get the most up-to-date state in an asynchronous function, you should copy the relevant part of state to a mutable reference so the function can read the reference during its execution. This is the same pattern you should use if you need to do the same with component input. #29 also introduces a useGet example Hook which makes this easy and convenient.