jsonapi-react icon indicating copy to clipboard operation
jsonapi-react copied to clipboard

Getting cannot read properties of undefined (reading 'ssrMode')

Open bhavesh1334 opened this issue 3 years ago • 2 comments

ss135

bhavesh1334 avatar Mar 11 '22 18:03 bhavesh1334

ss135

Getting this error from couple of days , tried enough but doesn't get any possible solution.

bhavesh1334 avatar Mar 11 '22 18:03 bhavesh1334

Hi @bhavesh1334,

It looks like the library could employ some better exception handling here, but the issue on your side appears to be that you are attempting to use useQuery outside the ApiProvider context.

Restructuring your code in the following manner should do the trick:

function App(props) {
  const query = useQuery('posts')
  
  return (
    <div>
      <h1>Hello</h1>
    </div>
  )
}

const root = (
  <ApiProvider client={client}>
    <App />
  </ApiProvider>
)

React.render(root, document.getElementById('root'))

aribouius avatar Apr 01 '22 23:04 aribouius