{data.devices.payload.map(device => ( <div> <Card className="card"> <CardContent> <TextField id="outlined-bare" defaultValue={device.name} margin="normal" variant="outlined" variables={{device.id}} onChange={e => this.setState({ name: e.target.value })} /> <Typography> Status: <span className={device.isOn === true ? "active" : "inActive"}>{device.isOn === true ? "W??CZONY" : "WY??CZONY"}</span> </Typography> </CardContent> <CardActions> <div className="wrapper"> <div className="buttonLeft"> <Mutation mutation={device.isOn === true ? SETOFF_MUTATION : SETON_MUTATION} variables={{ device.id }}> {mutation => ( <div className="button"> <Button variant="contained" color={device.isOn === true ? "secondary" : "primary"} onClick={mutation}> {device.isOn === true ? "WY??CZ" : "W??CZ"} <PowerSettingsNewIcon className="rightIcon" /> </Button> </div> )} </Mutation> </div>我只想將我的 device.id 從 map 函數(shù)傳遞到 Apollo Mutation。我可以使用其他值,例如 device.name。為什么我不能通過device.id?
如何將map函數(shù)中的變量放入Apollo變異變量中?
拉風的咖菲貓
2021-06-09 17:16:03