syncscroll icon indicating copy to clipboard operation
syncscroll copied to clipboard

Porting in React

Open alessandro308 opened this issue 4 years ago • 2 comments

I created a porting in React: https://codesandbox.io/s/usesyncscroller-3r6tu

alessandro308 avatar Aug 30 '21 09:08 alessandro308

use

useEffect(() => {
    if (names[id]) {
      names[id].push(ref);
    } else {
      names[id] = [ref];
    }
+    names[id] = names[id].filter((n) => n.current !== null);
  }, [id, ref]);

aquibbaig avatar Aug 22 '22 15:08 aquibbaig

use

useEffect(() => {
    if (names[id]) {
      names[id].push(ref);
    } else {
      names[id] = [ref];
    }
+    names[id] = names[id].filter((n) => n.current !== null);
  }, [id, ref]);

This will remove any references that have been created but not yet assigned. It would be better if the hook deletes its own reference when it's done. During synchronization, you just need to skip the null references.

evothreat avatar Nov 20 '22 12:11 evothreat