|
1 | | -import {useMemo, useState} from 'react'; |
| 1 | +import {useState} from 'react'; |
2 | 2 | import type {SharedValue} from 'react-native-reanimated'; |
3 | 3 | import {makeMutable, useAnimatedReaction} from 'react-native-reanimated'; |
4 | 4 | import {scheduleOnRN} from 'react-native-worklets'; |
@@ -96,34 +96,29 @@ function useChartInteractionState<Init extends ChartInteractionStateInit>( |
96 | 96 | state: ChartInteractionState<Init>; |
97 | 97 | isActive: boolean; |
98 | 98 | } { |
99 | | - const keys = Object.keys(initialValues.y).join(','); |
| 99 | + const yState = {} as Record<keyof Init['y'], {value: SharedValue<number>; position: SharedValue<number>}>; |
100 | 100 |
|
101 | | - const state = useMemo(() => { |
102 | | - const yState = {} as Record<keyof Init['y'], {value: SharedValue<number>; position: SharedValue<number>}>; |
103 | | - |
104 | | - for (const [key, initVal] of Object.entries(initialValues.y)) { |
105 | | - yState[key as keyof Init['y']] = { |
106 | | - value: makeMutable(initVal), |
107 | | - position: makeMutable(0), |
108 | | - }; |
109 | | - } |
110 | | - |
111 | | - return { |
112 | | - isActive: makeMutable(false), |
113 | | - matchedIndex: makeMutable(-1), |
114 | | - x: { |
115 | | - value: makeMutable(initialValues.x), |
116 | | - position: makeMutable(0), |
117 | | - }, |
118 | | - y: yState, |
119 | | - yIndex: makeMutable(-1), |
120 | | - cursor: { |
121 | | - x: makeMutable(0), |
122 | | - y: makeMutable(0), |
123 | | - }, |
| 101 | + for (const [key, initVal] of Object.entries(initialValues.y)) { |
| 102 | + yState[key as keyof Init['y']] = { |
| 103 | + value: makeMutable(initVal), |
| 104 | + position: makeMutable(0), |
124 | 105 | }; |
125 | | - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- keys is a stable string representation of y keys |
126 | | - }, [keys]); |
| 106 | + } |
| 107 | + |
| 108 | + const state: ChartInteractionState<Init> = { |
| 109 | + isActive: makeMutable(false), |
| 110 | + matchedIndex: makeMutable(-1), |
| 111 | + x: { |
| 112 | + value: makeMutable(initialValues.x), |
| 113 | + position: makeMutable(0), |
| 114 | + }, |
| 115 | + y: yState, |
| 116 | + yIndex: makeMutable(-1), |
| 117 | + cursor: { |
| 118 | + x: makeMutable(0), |
| 119 | + y: makeMutable(0), |
| 120 | + }, |
| 121 | + }; |
127 | 122 |
|
128 | 123 | const isActive = useIsInteractionActive(state); |
129 | 124 |
|
|
0 commit comments