Getting ref null inside useCallback hook

I’m trying to set the value of input using ref but I’m getting ref null inside useCallback Hook.

let inputRef = useRef();
const search = useCallback(
        (data) => {
            console.log(inputRef);
        },
        [inputRef],
    );

return <input type="text" ref={inputRef} />

and It’s showing null in the browser console when I call this function.

this is just an example showing, what I’m trying to achieve.

22 thoughts on “Getting ref null inside useCallback hook”

Leave a Comment