Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not re create dispatch on every call. #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Do not re create dispatch on every call. #5

wants to merge 3 commits into from

Conversation

amsterdamharu
Copy link

Dispatch has a different reference every time you call createDispatch.
That is not how React.useReducer works and this should have consistant behavior.

Reference to issiue: #4

Dispatch has a different reference every time you call createDispatch.
That is not how React.useReducer works and this should have consistant behavior.
@ahungrynoob
Copy link

@Tsourdox
Copy link

Tsourdox commented Jun 28, 2020

Why not just use the useRef hook to solve this? This PR seems overly complicated to me, maybe I'm missing something.

const { current: dispatch } = useRef(action =>
    Object.keys(combinedReducers)		
       .map(key => combinedReducers[key][1])		
       .forEach(fn => fn(action));
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants