Created
October 27, 2018 15:59
-
-
Save ernestofreyreg/cf9df19f9195b05aee7da8e97918ca0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
function useStateManager({ initialState, reducer, createActions }) { | |
const [state, dispatch] = React.useReducer(reducer, initialState) | |
const actions = createActions({ | |
getState: () => state, | |
dispatch: (type, payload) => | |
Promise.resolve(dispatch({ type, ...(payload || {}) })) | |
}) | |
return [state, actions] | |
} | |
export default useStateManager |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment