react-modal-hook
react-modal-hook copied to clipboard
React Hook "useState" cannot be called inside a callback.
const [showModal] = useModal(() => {
const [count, setCount] = useState(0);
return (
<ReactModal isOpen>
<span>The count is {count}</span>
<button onClick={() => setCount(count + 1)}>Increment</button>
</ReactModal>
);
});
return <button onClick={showModal}>Show modal</button>;
when I am trying to use demo code, got an error.
React Hook "useState" cannot be called inside a callback.
I did the workaround by define the whole component outside, then use like useModal(() => <MyComponent count={count} />, [count])