preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.79k stars 93 forks source link

Cleanup function used by useSignalEffect's callback isn't used #281

Closed jakearchibald closed 1 year ago

jakearchibald commented 1 year ago

From https://github.com/preactjs/signals/blob/main/packages/preact/src/index.ts#L345

export function useSignalEffect(cb: () => void | (() => void)) {
    const callback = useRef(cb);
    callback.current = cb;

    useEffect(() => {
        return effect(() => {
            callback.current();
        });
    }, []);
}

The signature of useSignalEffect suggests that, if cb returns a function, that function will be used somehow, but it isn't used in the implementation.

I'd expect the function returned by cb to be used in a similar way to useEffect, as in it's used as a cleanup function.