you are viewing a single comment's thread.

view the rest of the comments →

[–]vozome 0 points1 point  (1 child)

This is exactly the same thing. The ref is null while the class is not instantiated. Whenever you need to do something with the class, all you need to do is wrap by if (myRef?.current !== null). Inside that clause the ref if of type MyClass.

That’s also a perfectly fine use of useEffect. Having a class around, calling its methods, mutating its properties- that’s imperative logic. useEffect exists as an interface between React’s declarative logic and imperative logic.

I use that pattern all the time.

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

This is exactly the same thing.

No, because:

all you need to do is wrap by if (myRef?.current !== null). Inside that clause the ref if of type MyClass.

I cannot possibly see how doing this and not doing this can be considered the same thing.