The line
{toggleModal && <PopupModal onDoubleClick={setToggleModal(false)}/>}
Is immediately calling setToggleModal
with an argument of false when the component is rendered, and I believe undefined
becomes the value of onDoubleClick
. (Not 100% on if setState
has a return value or not)
To fix your problem you should provided this as a prop:
{toggleModal && <PopupModal onDoubleClick={() => setToggleModal(false)}/>}
This is providing a function definition rather than calling the function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…