I need to pass some props to a third-party drawing library, but I need to pass only the initial value of the prop. I've made a wrapper component which captures the initial props in state, and then passes them to the third-party component.
This works, but since setZoom and setCenter aren't used, it feels like an anti-pattern:
function Wrapper({ center, zoom }) {
const [initialZoom, setInitialZoom] = useState(zoom);
const [initialCenter, setInitialCenter] = useState(center);
return <ThirdParty zoom={initialZoom} center={initialCenter} />
}
I tried useMemo but eslint also warned about missing dependencies:
React Hook useMemo has a missing dependency: 'zoom'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps
function Wrapper({ center, zoom }) {
const initialZoom = useMemo(() => zoom, []); // eslint-disable-line react-hooks/exhaustive-deps
const initialCenter = useMemo(() => center, []); // eslint-disable-line react-hooks/exhaustive-deps
return <ThirdParty zoom={initialZoom} center={initialCenter} />
}
Is there an idiomatic way to do this? Or is it so non-standard that just ignoring the eslint warnings on the useMemo example is the best option?