How to use React.usecallback?

  javascript, reactjs, typescript

i have a function like below to be called on button click using react and typescript.

function Parent () {
    const [isOpen, setIsOpen] = React.useState(false);
    const handleClick = () => {
        setIsOpen(open => !open);
    }
    return (
        <button onClick={handleClick}>click me </button> 
    );

}

How can i rewrite handleClick method using React.usecallback method?

could someone help me with this. thanks.

Source: Ask Javascript Questions

LEAVE A COMMENT