简体   繁体   中英

Property 'then' does not exist on type 'RelayObservable<unknown>'. when I try to fetch data using relay in react. I don't know why this error come

Property 'then' does not exist on type 'RelayObservable'. when I try to fetch data using a relay in react.

  try {
            
            fetchQuery(environment, expenseQueryMyQuery,{}).then((data)=>{
                console.log("All data:::",data);
            }).catch((error)=>{
                console.log("query error::",error);
            })
           } catch (error) {
               
       }

If this really is an Observable, you should use .subscribe more than .then (which is intended for Promises)

fetchQuery(environment, expenseQueryMyQuery,{}).subscribe({
  next: (data)=>{
    console.log("All data:::",data);
  },
  error: (error)=>{
    console.log("query error::",error);
  }
})

Here's a link to the documentation for fetchQuery on the official website: https://relay.dev/docs/api-reference/fetch-query/#internaldocs-banner

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM