【发布时间】:2019-12-14 00:20:44
【问题描述】:
如何将 props 传递给 reactjs material dialog?如果我这样做< FormDialog value={this.prop.value} />,则抛出Type '{ value: any; }' is not assignable to type 'IntrinsicAttributes' 错误。我如何为FormDialog() 分配类型或以任何其他方式将道具传递给该组件?
Modal.tsx
export default function FormDialog() {
const [open, setOpen] = React.useState(false);
function handleClickOpen() {
setOpen(true);
}
function handleClose() {
setOpen(false);
}
return (
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open form dialog
</Button>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Subscribe</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
id="name"
label="Email Address"
type="email"
fullWidth
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="primary">
Subscribe
</Button>
</DialogActions>
</Dialog>
</div>
);
}
Card.tsx
class ShipmentCard extends Component<ShipmentCardProps, ShipmentCardState> {
render() {
return (
<Card className="Card">
<CardContent className="Card-Content">
<FormDialog />
<Grid container spacing={3}>
<h3 className="Card-Content__Title">{this.props.value.name}</h3>
<FormDialog />{/*how i can pass this.props.value */}
</Grid>
</CardContent>
</Card>
);
}
}
【问题讨论】:
-
不需要将组件定义为获取道具吗?
-
@Dave,我尝试将
FormDialog作为组件,但它不起作用。你知道有什么更好的方法来实现吗?
标签: reactjs modal-dialog pass-data react-tsx react-material