【发布时间】:2020-09-19 12:30:22
【问题描述】:
我想在访问屏幕时打开对话框,所以我将默认状态设置为 true。我做了一个自定义按钮。当我单击它时,状态应更改为 false 并且对话框应关闭。但是,对话框不会关闭。我做错了什么,我还能如何关闭对话框?
<Dialog open={openReminder}>
<DialogTitle>Reminder</DialogTitle>
<DialogContent>
<DialogContentText>Don't forget to take your daily walk!</DialogContentText>
<div className={classes.reminderContainer}>
<DialogButton
text={"Ok, thanks!"}
onPress={() => setOpenReminder(false)}
/>
</div>
</DialogContent>
</Dialog>
export const DialogButton = ({ onPress, text }) => {
const classes = useStyles();
return (
<Button onPress={onPress} className={classes.button}>
{text}
</Button>
);
};
【问题讨论】:
-
您是否尝试使用
onPress作为 DialogButton 中的道具?你能从这个组件中添加你的代码吗? -
你的意思是
onClick而不是onPress? -
将它与 React Native 混合,哎呀@NearHuscarl
标签: javascript reactjs typescript dialog material-ui