No-op reducer in Reason React
Generally in ReasonReact if you have a reducer component that component will have a reducer function that looks like this:
``` reason
reducer: (action, state) => {
switch(action) {
| Change(newValue) =>
ReasonReact.Update({value: newValue})
}
}
```
`ReasonReact.Update` is a variant that constructs with a state value.
Another variant you can return from the reducer function is `ReasonReact.NoUpdate`, allowing you to not update the state if circumstances do not warrant it.
``` reason
reducer: (action, state) => {
switch(action) {
| Change("UghWat") =>
ReasonReact.NoUpdate
| Change(newValue) =>
ReasonReact.Update({value: newValue})
}
}
```
Not if the user enters "UghWat" we won't update the state with that useless value.
chriserin
July 22, 2018