你的 `handleClick` 异步函数为什么会出现错误?

huangapple go评论64阅读模式
英文:

why i got an error in my handleClick async function?

问题

我尝试在我的突变变量中添加display_1和display_2,然后尝试console.log它,但console.log(data, loading, error)的输出为(undefined, false, undefined)

const CREATE_T09_SCREENSHOT = gql
mutation
createT09ScreenShot(
$screenshot_window_1: String!,
$screenshot_window_2: String!,
) {
createT09ScreenShot(
screenshot_window_1: $screenshot_window_1,
screenshot_window_2: $screenshot_window_2,
) {
screenshot_window_1
screenshot_window_2
}
}
;
const SaveLogsButton = () => {
const [createT09ScreenShot, { loading, error, data }] = useMutation(CREATE_T09_SCREENSHOT);

const handleClick = async () => {
const screenshotData = await saveImage();
if (screenshotData){
const { display_1, display_2 } = screenshotData;
createT09ScreenShot({
variables: {
screenshot_window_1: display_1,
screenshot_window_2: display_2,
},
});
}
console.log(data)
console.log(loading)
console.log(error)
};



我还尝试这样做,但它给我一个错误 

const handleClick = async () => {
await saveImageFunction();
const { display_1, display_2 } = saveImage;
createT09ScreenShot({
variables: {


这是错误信息

Unhandled Promise Rejection: TypeError: Right side of assignment cannot be destructured

英文:

i tried to add the display_1 and diplay_2 in my mutation variables and tried to console.log it but the output is (undefined, false, undefined) for the console.log(data,loading,error)

const CREATE_T09_SCREENSHOT = gql`
  mutation 
    createT09ScreenShot(  
      $screenshot_window_1: String!, 
      $screenshot_window_2: String!,  
    ) { 
    createT09ScreenShot(
       screenshot_window_1: $screenshot_window_1, 
       screenshot_window_2: $screenshot_window_2, 
    ) { 
       screenshot_window_1
       screenshot_window_2
      } 
    }
`;
const SaveLogsButton = () => {
  const [createT09ScreenShot, { loading, error, data }] = useMutation(CREATE_T09_SCREENSHOT);
  
  const handleClick = async () => {
    const screenshotData = await saveImage();
    if (screenshotData){
    const { display_1, display_2 } = screenshotData;
    createT09ScreenShot({
      variables: {
        screenshot_window_1: display_1,
        screenshot_window_2: display_2,
      },
    });
  }
    console.log(data)
    console.log(loading)
    console.log(error)
  };

i also tried to do this but it give me an error

  const handleClick = async () => {
    await saveImageFunction();
    const { display_1, display_2 } = saveImage;
    createT09ScreenShot({
      variables: {

and here is the error

Unhandled Promise Rejection: TypeError: Right side of assignment cannot be destructured

答案1

得分: 0

我认为你在saveImage destructurable对象的handleClick函数内部有一些错误。

你需要使用以下代码替换你的handleClick函数代码:

const handleClick = async () => {
    const screenshotData = await saveImageFunction();
    const { display_1, display_2 } = screenshotData;
    createT09ScreenShot({
        variables: {
            screenshot_window_1: display_1,
            screenshot_window_2: display_2,
        },
    });
};
英文:

I think you have some error inside handleclick function of saveImage destructurable object.

You need to replace your handleClick function code with this code:

const handleClick = async () => {
    const screenshotData = await saveImageFunction();
    const { display_1, display_2 } = screenshotData;
    createT09ScreenShot({
      variables: {
        screenshot_window_1: display_1,
        screenshot_window_2: display_2,
      },
    });
};

huangapple
  • 本文由 发表于 2023年2月10日 12:44:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定