Home > Net >  ReactQuery Typescript how to type query
ReactQuery Typescript how to type query

Time:01-28

hello why i have typescript error? enter image description here

enter image description here

enter image description here

enter image description here

CodePudding user response:

LibraryContext.Provider is expecting libraryType.

While react query does its work the default value is undefined.

So you may need to do something like this:

const defaultLibraryValue = {
 name: '',
 address: '',
 phone: ''
//Add a default to each property of libraryType
} as libraryType; 

<LibraryContext.Provider value ={{library: data === undefined ? defaultLibraryValue : data}}
  • Related