I shouldn’t have mentioned orbit controls, i meant mostly things like new Vector3 i just didn’t want the constructor to be called all the time, regardless of any side effects inside.
But interesting points were brought up here.
Going to this useMemo that was linked, the example definitely uses them:
const geom = useMemo(() => new BoxGeometry(), [])
const mat = useMemo(() => new MeshBasicMaterial(), [])
return items.map(i => <mesh geometry={geom} material={mat} ...
I only found out about the comment above recently, so i guess they never made that change, but this example is basically risky? Either useState or useRef would guarantee that it’s stable, useMemo does not. At least according to Dan Abramov, an authority on React, it seems that it’s an anti pattern.
Is it fair to assume that there are a lot of three fiber apps our there that heavily leverage useMemo for these “I need to instantiate something once when the component mounts”? If so, is what Dan Abramov mentioned ever going to be a problem?
The other interesting point is:
@AshhadDevLab I hope this answers a bit of your question. Orbit controls were already there, but someone needed a slightly different version, so they forked it. This is very common in open source i think.
I whipped this up in a few hours, kind of a blend between orbit controls and trackball controls. Those are all just examples anyway.
So to reiterate useMemo is not from three-fiber AND it doesn’t do this (or what i need).
useThree may be from react-fiber but im not using it, three is instantiated somewhere outside of react and all that.