Sorry new React guy here and cant for the life of me figure out this issue.
This is just the necessary code snippets of my app but Im just trying to get the contents of the clicked Datagrid row, pass to the Dialog form and then call my other component passing the row info. I get the row info no problem. It just never shows up in the props on the second component. I can pass anything else just fine to the other component (text, variable etc..) Just not the setsendRowInfo info. Any help would be apprectiated!
let [sendRowInfo, setsendRowInfo] = useState([]);
function DataTable(){
const handleOnCellClick = (params) => {
setOpen(true);
name = params.row;
setsendRowInfo = params.row;
};
}
return (
<div style={{ height: 700, width: "100%" }}>
<DataGrid
{...tableData}
slots={{
toolbar: CustomToolbar,
}}
rows={tableData}
columns={columns}
pageSize={10}
containerBackground="#fff"
checkboxSelection
disableRowSelectionOnClick
onRowClick={handleOnCellClick}
columnVisibilityModel={{
id: false,
}}
<Dialog open={open} onClose={handleClose}>
<Slide direction="down" in={open} mountOnEnter unmountOnExit>
<DialogTitle className="titleaddnew">
<img className="logo" src={Logo} alt="logo" />
<strong>Enter Application Info:</strong>
</DialogTitle>
</Slide>
<DialogContent>
<div>
<MyForm send = {{setsendRowInfo}} />
</div>
</DialogContent>
</Dialog>
;
</div>
);
}
export default DataTable;
function MyForm(props) {
let [rowResults, setrowResults] = useState();
setrowResults = props.send;
console.log(setrowResults );
Tried passing the state multiple different ways to no avail .
2
Answers
Basic usage of useState is kinda different than yours.
useState
Possible fix :
I don’t know about how you prepared props for
but if it hasn’t any problem just pass the sendRowInfo
depends on how you declared the send prop in MyForm it may be
Here is a suggested solution. Comments have been added where changes are made.
Also, take note of the little improvement on the MyForm function: