Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Dispatch re-renders components even when state is unchanged. #215

@js-jslog

Description

@js-jslog

I am using reactn on 2.2.7 and react on 16.13.1

The react docs on useReducer imply that the state property being dispatched to will not actually be updated if the next value is identical to the previous one: https://reactjs.org/docs/hooks-reference.html#bailing-out-of-a-dispatch (it talks about components not rerendering but presumably the ultimate cause of that is that the state has not been updated)

It looks to me as though this same convention is not being observed in the reactn useDispatch with a global inline property reducer (https://github.com/CharlesStover/reactn#usedispatchfunction-keyof-state) which I would consider an equivalent use case.

// use-dispatch.js - when this dispatch is run...
...
const dispatch = useDispatch((prevStateItem) => prevStateItem, 'stateItem')
dispatch()
...
// component.jsx - ...this component is rerendered
...
const [stateItem] = useGlobal('stateItem')
...

I'm curious to know whether this is known and deliberate, unknown and of interest, or just plain wrongly observed of me.

I'm happy to provide more detailed explanation and examples if it would be helpful.

Thank you for the reactn project. It's been a joy to work with, not least because of the excellent documentation and articles. It's very intuitive and follows from reacts hooks nicely which is obviously a goal of the project. Congratulations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions