Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useEffect in custom hook not triggered when 'ref' changes #25

Open
sorskoot opened this issue Dec 18, 2024 · 0 comments
Open

useEffect in custom hook not triggered when 'ref' changes #25

sorskoot opened this issue Dec 18, 2024 · 0 comments

Comments

@sorskoot
Copy link
Contributor

When a hook depends on a 'ref' and that ref changes in the component, because it was used in a condition for example that became active after the component was first rendered, the useEffect in the hook doesn't get called. A useEffect in the component itself does. This allows for working around it, but that is not ideal.

export const useSomeHook = (
    props: SomeHookProps
): [React.MutableRefObject<Object3D | null>] => {
    const ref = useRef<Object3D>(null);
    useEffect(() => {
        // Do something with the ref.current, but this gets never called.
    }, [ref.current]);
    return [ref];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant