syncscroll
syncscroll copied to clipboard
Porting in React
I created a porting in React: https://codesandbox.io/s/usesyncscroller-3r6tu
use
useEffect(() => {
if (names[id]) {
names[id].push(ref);
} else {
names[id] = [ref];
}
+ names[id] = names[id].filter((n) => n.current !== null);
}, [id, ref]);
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.