Smart is a very small library which helps decouple state management and non-ui-related actions to separate classes. Behind the scenes it's just hooks, nothing fancy.
Let us a imagine a counter model:
Above we see that our model only has an initial state, and then it exposes certain actions and uses
setState to introduce the new
Using it can be done like this:
Another, more verbose way to create it would be like this:
This would be helpful when you want to have multiple
hooks in the same component.
The model can be configured and act differently based on a configuration it receives:
Using this is super easy:
There is another argument called
options when creating a smart:
To be able to properly manipulate complex models with state, we recommend immer