Skip to content

useMap's set() should not re-render when setting a key to the same value it's currently set to #1655

Open
@benface

Description

@benface

What is the current behavior?

const [count, setCount] = useState(0)
const map = useMap([['count', 0]])

console.log('rerender')

return <>
  <button type="button" onClick={() => setCount(0)}>Click state</button>
  <button type="button" onClick={() => map.set('count', 0)}>Click map</button>
</>

Clicking on the "Click state" button multiple times in a row shows "rerender" only once in the console, whereas clicking on the "Click map" button shows it for every click.

Steps to Reproduce

See above.

What is the expected behavior?

It should behave like useState().

Environment Details

  • @react-hookz/web version: 25.1.1
  • react version: 18.3.21
  • react-dom version: 18.3.7
  • typescript version: -
  • OS: macOS
  • Browser: Chrome, Safari, and Firefox
  • Did this work in previous versions? I don't know

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions