后端突变完成后设置React状态?

时间:2020-11-02 07:56:43

标签: reactjs express graphql apollo

我正在尝试通过以下突变通知on('finished')处的前端。我看过一些相当冗长的教程like this,以了解如何做,但似乎远远超出了我的需要。

我只想能够在图像上传完成后在React中更改状态。我正在使用Recoil,因此在我的情况下,它将设置一个uploadingState原子。

Mutation: {
  uploadFile: async (_, { file }) => {
    const { createReadStream, filename } = await file;
    await new Promise(res =>
      createReadStream()
        .pipe(
          wudditBucket.file(filename).createWriteStream({
            resumable: false,
            gzip: true,
          }),
        )
        .on('finish', res), // setRecoil atom when this is fires?
    );
    files.push(filename);
    return true;
  },
},

0 个答案:

没有答案