-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate actions and reducers once instead of every render
- Loading branch information
doniyor2109
committed
Dec 26, 2018
1 parent
405d9c2
commit 88a4a34
Showing
2 changed files
with
6 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { useReducer } from 'react' | ||
import { useReducer, useMemo } from 'react' | ||
|
||
import { createUpdater } from './createUpdater'; | ||
import { bindActionCreators } from './helpers'; | ||
|
||
export function useUpdater(Updater) { | ||
const [reducer, actions, initialState] = createUpdater(Updater) | ||
const [reducer, actions, initialState] = useMemo(() => { | ||
return createUpdater(Updater) | ||
}, []) | ||
const [state, dispatch] = useReducer(reducer, initialState) | ||
return [state, bindActionCreators(actions, dispatch)] | ||
} |
This file contains 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
88a4a34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #1