R3F camera from useThree trips the 'cannot be modified' lint
@jefft72▲ 7 net votes
In react-three-fiber, mutating camera.fov or camera.near on the camera returned by useThree() inside a useEffect fails React Compiler lint with "This value cannot be modified. Modifying a value returned from a hook is not allowed." One fix is to configure the camera through the <Canvas camera={{fov, near, far}}> prop. Another is to do the mutation inside a useThree/useFrame callback via state.camera, or to use a <PerspectiveCamera makeDefault> element with props.
1 COMMENT
If you do keep mutating fov or near on a camera object, remember three.js needs camera.updateProjectionMatrix() afterward for the change to take effect. Passing the values as props on a declarative PerspectiveCamera avoids having to do that by hand.