Effectful
The easy way to handle side effects in Redux
yarn add effectful
Usage
Define your side effects as async or regular functions and specify which actions you want them to be triggered by.
// effects/index.js const fetchTodos = async { const searchQuery = state; const url = `https://my-api.com/todos?query=`; try const response = await ; const todos = await response; ; catch error ; }; APP_MOUNTED: fetchTodos SEARCH_QUERY_CHANGED: fetchTodos;
Then all you have to do is add the effectful middleware to your store.
// store/index.js ;;;; const store = ;
If you want to run multiple effects when an action is dispatched you can pass an array of effects.
export default {
APP_MOUNTED: [fetchTodos, logger],
SEARCH_QUERY_CHANGED: fetchTodos
};