Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Non-memoized / ref'd reducer runs into double dispatch issue when used in custom hook #18

Open
@chrisdhanaraj

Description

@chrisdhanaraj

Hello! First off, love this library so much, it's made my code so much more clean.

Simplified reproduction:https://codesandbox.io/s/red-https-bxpo0?file=/src/App.tsx

But anyways, I've run into this scenario recently and was able to resolve by resolving this locally - but, to be honest, I'm not really sure of the React internals enough to PR this + test. Anyways, the scenario

  1. I want to useuseEffectReducer in my own hook and export out it's dispatch so that other components can programmatically send out events to the reducer.
  2. However, when I leverage the dispatch it emits events twice.
  3. To resolve, you canuseMemo thewrappedReducer .
const memoReducer = useMemo(() => wrappedReducer, []);const [[state, effectStateEntityTuples, entitiesToStop], dispatch] = useReducer(    memoReducer,    initialStateAndEffects );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp