-1
Personal talk,
I set up a page that has a menu (inside the file "Menu.jsx"), in this menu has a button, I want to open a "dialog", like a pop-up to register notes. This dialog has its own file "Cadastro.jsx"
Menu.jsx
...
export default function ButtonAppBar() {
const classes = useStyles();
return (
<div className={classes.root}>
<AppBar position="static">
<Toolbar>
<Button variant="contained"
style={{ marginRight: 50 }}
**onClick={() => ???????}**
>Cadastrar Notas</Button>
<Typography variant="h5" className={classes.title}>
Calculadora Darf IR Trader
</Typography>
<Button color="inherit">Ajuda</Button>
</Toolbar>
</AppBar>
</div>
);
}
Cadastro.jsx
export default function FormDialog() {
const [open, setOpen] = React.useState(false);
const handleClickOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
<DialogTitle id="form-dialog-title">Cadastro de Notas</DialogTitle>
<DialogContent>
<DialogContentText>
...
Thank you Lucas, I did as you explained and the "onClick" didn’t work, but I confess that I did "in a hurry" so it might have passed something that was left out. I am here with a tabs to read about "useState" and props, I will study better and see where I went wrong. As soon as I get put here as I did.
– TadeuTr
Strange, it should work, I noticed that in these examples you didn’t use any props, and I don’t know how much you already know the syntax, but the props are always objects! So it should be +- so the signature of the functions: Buttonappbar({ handleClickOpen }) But the idea is this, if sibling components need to talk to each other, you should use the parent component as "postman" in this communication.
– Lucas de Oliveira