I am using react-three-fiber, and I have a geometry that changes asynchronously according to some variables in a useEffect. I am keeping this geometry isolated because I want to reuse it later accross different components. Like this:
const Geom = (props) => {
const [isCube, setIsCube] = useState(false)
useEffect(() => {
// do something that changes geometry asynchronously
setIsCube(props.thing)
}, [props])
return (
<>
{isCube ? <boxGeometry/> : <sphereGeometry/>}
</>
)
}
And I use it in many places:
const firstMesh = (props) => {
return (
<mesh><Geom/><material/></mesh>
)
}
const secondMesh = (props) => {
return (
<mesh><Geom/><differentMaterial/></mesh>
)
}
My issue is that whenever the variables change and the useEffect gets fired (I know its being fired because breakpoints there activate) the other meshes dont “notice” this change and remain the same, until I change another one of their properties, which prompts a rerendering with the appropriate geometry. What am I doing wrong? I feel like this is a simple thing.