Skip to content

Commit 5151558

Browse files
committed
fix: better cursor syncing
1 parent 8803434 commit 5151558

File tree

2 files changed

+1830
-1826
lines changed

2 files changed

+1830
-1826
lines changed

src/components/Cursors.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,18 @@ function Cursor<TDatum>(props: {
106106
: axis.getValue(d?.originalDatum)
107107
: undefined
108108

109-
const preValue = resolveValue(focusedDatum)
109+
const datumValue = resolveValue(focusedDatum)
110110

111111
React.useEffect(() => {
112-
getTooltipOptions()?.onChange?.(preValue)
113-
}, [getTooltipOptions, preValue])
112+
getTooltipOptions()?.onChange?.(datumValue)
113+
}, [getTooltipOptions, datumValue])
114114

115-
const value = props.options.value ?? preValue
116-
const latestValue = props.options.value ?? resolveValue(latestFocusedDatum)
115+
const value = props.options.value ?? datumValue
116+
117+
const latestValue = useLatestWhen(
118+
props.options.value ?? resolveValue(latestFocusedDatum),
119+
typeof props.options.value !== 'undefined'
120+
)
117121

118122
// Get the sibling range
119123
const siblingRange = siblingAxis.scale.range()

0 commit comments

Comments
 (0)