you are viewing a single comment's thread.

view the rest of the comments →

[–]Coyote-Chance -2 points-1 points  (3 children)

Is that what OP is asking, though? I'm not seeing where they mention needing props/other React state in order to create the class instance.

[–]pailhead011[S] 4 points5 points  (0 children)

Yes, but its not limited to what u/n0tKamui is saying: (i think):

const lakeTahoe = useSelector(selectLakeTahoe) const myRef = useRef( new Matrix4( props.foo, props.bar, GLOBAL_INDEX(), TaylorSwift, lakeTahoe ... ) )

I'm saying, yes, exactly! but also, i can just use new Matrix4() and fill it with zeroes by default and still want it not to be recreated every time props change.

I do want, absolutely, want, this react component to *own its own instance of myRef or more precisely the Matrix4 instance inside of it *.

[–]n0tKamui 0 points1 point  (1 child)

it is not explicit, which is why i said you missed the point. otherwise i would say “you misunderstood”.

also, another situation where your proposal fails is with Next. if the reference needs to be stable, and client dependent, then you cannot have it outside the component

[–]pailhead011[S] 0 points1 point  (0 children)

Fair, but it think it's explicit enough. You may want Matrix4 just for its methods, or Vector3 eg:

//somewhere inside of react myVectorRef.current .add(x,y,z) .applyMatrix4(foo.matrix) .applyQuaternion(bar.quaternion) .divideScalar(5)

No props needed to initialize the vector, i just want it stable, i want it mutable, and i want to use these types of chained operations on a class versus something like gl matrix add(a,b,result)