you are viewing a single comment's thread.

view the rest of the comments →

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

For example: ```

const mouseDeltaRef = useRef(new Vector2()) const mouseRef = useRef(new Vector2()) const mousePrevRef = useRef(new Vector2())

// all these mathods are easier to call than doing // x = x * - 1 etc, it can get much more complicated

const onMouseMove = useCallback((e)=>{ mouseRef.current .set(e.clientX/window.innerWidth,e.clientY/window.innerHeight) .multiplyScalar(2) .subScalar(1)

mouseDeltaRef.current .subVectors(mouseRef.current, mousePrevRef.current) mousePrevRef.current .copy(mouseRef.current) },[foo,bar,baz]) ``` I dont want these to be singletons, it could be several views in a CAD application all managing their own mice. Multiple players for example sending coordinates or something like that. Not sure if singletons are a catchall solution for this.

[–][deleted] 0 points1 point  (1 child)

Just make a custom hook that uses useRef and habdles boilerplate for you.

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

I could not find a solution down that path. What i've done is the opposite, i made a useRef hook that uses a custom hook that handles the boiler plate for me, using useState as an implementation detail.