In Vanilla scenarios, please import all APIs from /vanilla.
Create a store with an initial state.
A store can be global or local, depending on your needs.
If you need to debug, you can enable Redux DevTools Extension support by using devtools. For more details, see Integrating with Redux DevTools.
Subscribe to store to get notified when state changes.
Directly modify the store.mutate object to update the state in store.
If you just want to read the state, you can directly read the store.mutate object while following the immutable principle.
The above method covers most cases. If you really need to get a snapshot, you can use store.snapshot().
If needed, you can also easily restore to the initial state using store.restore(), for example, when stopping or resetting logic.
store.restore() uses the newer structuredClone API. If necessary, consider adding a polyfill.