The useMediatedState hook mimics the React useState hook’s return value, which means that setState expects either a value or an updater function.
This creates a problem as the mediator function receives both values and functions, which is unintuitive and inconvenient.
This PR addresses the issue by ensuring that if setState is given an updater function, the hook will first execute this function to compute the new state. It will then pass the resulting value to the mediator. Additionally, initializer functions are now supported for improved flexibility.
Type of change
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change(fix or feature that would cause existing functionality to not work as before)
Description
The
useMediatedState
hook mimics the ReactuseState
hook’s return value, which means thatsetState
expects either a value or an updater function.This creates a problem as the mediator function receives both values and functions, which is unintuitive and inconvenient.
This PR addresses the issue by ensuring that if
setState
is given an updater function, the hook will first execute this function to compute the new state. It will then pass the resulting value to the mediator. Additionally, initializer functions are now supported for improved flexibility.Type of change
Checklist
yarn test
)yarn lint
). Fix it withyarn lint:fix
in case of failure.yarn lint:types
).