Skip to content

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

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

Activity

  1. sridharkalaibala commented on Sep 12, 2026

    @sridharkalaibala

    I would like to address this with an Object.is comparison before scheduling a render for set(), while still inserting missing keys whose value is undefined. I will add render-count regressions for unchanged/changed values, NaN, signed zero, object identity, and preserve Map.set chaining; clear/delete behavior will stay outside this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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