react-native-stonk-charts
Version:
A beautiful, performant chart library for React Native. Fork of react-native-wagmi-charts with Reanimated v4 support.
18 lines (14 loc) • 611 B
text/typescript
import { useDerivedValue } from 'react-native-reanimated';
import type { TCandle } from './types';
import type { SharedValue } from 'react-native-reanimated';
import { useCandlestickChart } from './useCandlestickChart';
export function useCandleData(): Readonly<SharedValue<TCandle>> {
const { currentX, data, step } = useCandlestickChart();
const candle = useDerivedValue(() => {
if (currentX.value === -1) {
return { timestamp: -1, low: -1, open: -1, high: -1, close: -1 };
}
return data[Math.floor(currentX.value / step)] as TCandle;
}, [currentX, data, step]);
return candle;
}