Hey, just getting started with react-three-fiber and I have issues understanding how the “data flows”. I have a plane and a VideoTexture, and want to update the plane size when the video was loaded. My r3f component looks like this:
export function VideoPlane(props) {
const [width, setWidth] = useState(1);
const map = useVideoTexture(props.src, {
onloadedmetadata: function() {
console.log('new width', this.videoWidth / this.videoHeight);
setWidth(this.videoHeight / this.videoWidth);
}
});
return (
<mesh scale={[width, 1, 1]}>
<planeGeometry />
<meshBasicMaterial map={map} />
</mesh>
)
}
I see the correct width log but console gives warning: Can’t perform a React state update on a component that hasn’t mounted yet. This indicates that you have a side-effect in your render function that asynchronously later calls tries to update the component. Move this work to useEffect instead.
I tried this a few different ways but always end up with the same errors. Any ideas? (I’m using drei useVideoTexture)