我想通过materialId和supplyId更新mongoDB文档中的记录。 我从URL路径获取SupplyId以进行突变。我使用“ +”按钮为列出的所有材料进行渲染。如何将道具传递给变异变量?我试过了,但这很糟糕。
materialId: {material.id},
Scren from React Developers Tools
<Query
query={gql`
{
materials {
id
name
}
}
`}
>
{({ loading, error, data }) => {
if (loading) return <div>Fetching</div>;
if (error) return <div>Error</div>;
else
return (
<div>
Materials to add:
<ul>
{data.materials.map(material => (
<li id={material.id} key={material.id}>
{material.name} |
<Mutation
mutation={SUPPLY_MUTATION}
propsId={material.id}
variables={{
materialId: "get material.id Here",
supplyId: this.props.match.params.id
}}
>
{supplyMutation => (
<button onClick={supplyMutation}>+</button>
)}
</Mutation>
</li>
))}
</ul>
</div>
);
}}
</Query>
答案 0 :(得分:0)
您应该使用:
materialId: material.id