I am using unstated-next in a project. I found some situations where I couldn't use unstated-next and had to write contexts, providers and hooks myself. These were caused by following limitation of unstated-next.
1. Only initial state
Only initial state can be passed to providers. This makes it impossible to use unstated-next in certain situations. Initial state can be easily implemented in the function passed to createContainer using useState. So I think providers should always pass the state directly.
2. Only one prop on provider
Providers only accepts one prop named initialState. Making this configurable will be helpful.
Problems
I am using unstated-next in a project. I found some situations where I couldn't use unstated-next and had to write contexts, providers and hooks myself. These were caused by following limitation of unstated-next.
1. Only initial state
Only initial state can be passed to providers. This makes it impossible to use unstated-next in certain situations. Initial state can be easily implemented in the function passed to
createContainer
usinguseState
. So I think providers should always pass the state directly.2. Only one prop on provider
Providers only accepts one prop named
initialState
. Making this configurable will be helpful.Possible solution
JS
TS
Notes
The type of the first argument can be used to determine the props of the provider. The provider can pass its props object directly to useContainer.