Use listeners instead
While thunks definitely work, it's recommended to use the newer listeners plugin instead. Listeners support everything thunks do and more. Plus they are integrated directly into kea.
Thunks are simple ways to define side effects in Kea. They use
under the hood.
Then install the plugin:
You define thunks in a block called
thunks. Whatever you define there can be called through
for example in the
useActions hook or directly inside the logic:
Here is an example of thunks in action:
As you can see, you have access to the standard Redux
However you don't need to call
dispatch before any action in the actions object.
They are wrapped automatically.
The current thunk plugin (v1.0.0) does not support
autoConnect. That means if you want to call
inside a thunk, you must first make sure
otherLogic is connected to your logic: