Repository navigation
Commit 965ca70
committed
fix(react): don't call useCallback conditionally in MiniMap
onSvgNodeClick was built with a useCallback inside a ternary, so the hook
only ran when onNodeClick was provided. Two problems followed:
- toggling onNodeClick between undefined and a function changes the hook
count and React throws "Rendered more hooks than during the previous
render"
- the empty dependency array pinned the callback to the onNodeClick from
the first render, so handlers that close over props or state kept using
stale values
Call the hook unconditionally and read the handler through a ref, so the
callback identity stays stable for the memoized minimap nodes while always
invoking the current onNodeClick. onSvgNodeClick is still undefined when
no handler is passed.1 parent 6eee160 commit 965ca70
2 files changed
Lines changed: 18 additions & 6 deletions
File tree
- .changeset
- packages/react/src/additional-components/MiniMap
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
150 | 157 | | |
151 | 158 | | |
152 | 159 | | |
| |||
0 commit comments