Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Apollo客户端-变异检测变异完成,然后运行代码_Reactjs_Graph_Apollo Client_React Apollo - Fatal编程技术网

Reactjs Apollo客户端-变异检测变异完成,然后运行代码

Reactjs Apollo客户端-变异检测变异完成,然后运行代码,reactjs,graph,apollo-client,react-apollo,Reactjs,Graph,Apollo Client,React Apollo,我试图实现一个更新函数,因此,我使用GraphQL变异。但是,我需要能够检测突变何时完成,以便运行刷新功能 到目前为止,对于突变,我有: const handleParameterUpdate = () => { let active = true; (async() => { await updateParameterMutation({variables: { parameterId: props.parameter.i

我试图实现一个更新函数,因此,我使用GraphQL变异。但是,我需要能够检测突变何时完成,以便运行刷新功能

到目前为止,对于突变,我有:

const handleParameterUpdate = () => {
    let active = true;

    (async() => {
 
        await updateParameterMutation({variables: {
           parameterId: props.parameter.id, 
           newField: newFieldValue;
        }});

        if (!active) {
            return;
        }
        
    })().then(props.updateParams());
    
}
在父组件中,我有:

const handleRefresh = () => {
    refetchJobParams({
        id: parent.id
    });
}

我的目的是在变异完成后运行
handleRefresh
函数。到目前为止,它会在
handleParametersUpdate之后立即运行,因此,我需要刷新以获取新参数。

我在这里看不到您的用法。但是,
usemotation
hook有一个选项,可以添加一个
onCompleted
回调,成功后将调用该回调。如果您也在从apollo查询中重新提取某些内容,那么我建议您也使用
refetchQueries
选项。这使您可以编写更少的代码,并让Apollo处理重新蚀刻和完成回调

但是,在代码中,如果希望在
handleParameterUpdate
内部运行
handleRefresh
,则可以提取突变返回的任何值

const handleParameterUpdate = async () => {    
    const returnValue = await updateParameterMutation({variables: {
       parameterId: props.parameter.id, 
       newField: newFieldValue;
    }});

    // whatever check you need to do on your mutation,
    if (returnValue){
        handleRefresh();
    }
}