@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
26 lines (23 loc) • 552 B
text/typescript
import { useEffect, useMemo } from "react";
import {
useSharedValue,
runOnJS,
startMapper,
stopMapper,
} from "./moduleWrapper";
export const useDerivedValueOnJS = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fn: () => any,
deps: unknown[]
) => {
const init = useMemo(() => fn(), [fn]);
const value = useSharedValue(init);
useEffect(() => {
const mapperId = startMapper(() => {
"worklet";
runOnJS(fn)();
}, deps);
return () => stopMapper(mapperId);
}, [deps, fn]);
return value;
};