Middleware Hooks
useThunk
useThunk
useThunk
enables action creators to return a function.
Inspired from redux-thunk.
Usage
import { useThunk } from 'middleware-hooks';const App = () => { const [store, dispatch] = useThunk(reducer, initialState); return <h1>Hello World!</h1>;};
Sample Action creators
function incrementIfOdd() { return (dispatch, getState) => { const { counter } = getState(); if (counter % 2 === 0) { return; } dispatch(increment()); };}const onButtonClick = () => dispatch(incrementIfOdd());