Modal对话框关闭后状态没重置怎么办?
我用React写了个Modal弹窗,点“取消”关闭后,下次打开表单内容还是上次填的,怎么清空啊?试过在onClose里设state,但好像没生效。
这是我的关键代码:
const [open, setOpen] = useState(false);
const [inputValue, setInputValue] = useState('');
const handleClose = () => {
setOpen(false);
// 这里加了也没用?
setInputValue('');
};
return (
<div>
<button onClick={() => setOpen(true)}>打开</button>
<Modal open={open} onClose={handleClose}>
<input value={inputValue} onChange={e => setInputValue(e.target.value)} />
</Modal>
</div>
);
暂无解答