Skip to content

Reducer action beeing dispatched twice #11

Open
@Stene3

Description

@Stene3

Hi @Jibbedi,

at first I would like to say thanks for this great library. I was searching for a replacement of ngrx effect in my react application after transition from angular to react stack, but I also found a weird issue when used with FC component.

I didnt have time to analyze it more, so more details will come as soon as possible, but maybe you will have more ideas about a workaround.

When I use useReducerWithSideEffects inside the FC component which stays as a Context provider, and call an async method from the child component available from the context state, every reduce action will cause re-rendering the provider component, which, probably, re-creates useReducerWithSideEffects which will cause for the same action being dispatched again.

image

I will add a sandbox example, but maybe you also came into the same issue previously when writing this library.

Thanks,
L.


Update 1: I've checked your code which mentions the issue when StrictMode is used, but it's not this issue. Same issue occurs when StrictMode is not used. I also tried to use memoized callback for reduce and effect when creating side effect reducer, but this did not help either.

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