aribouius / jsonapi-react

A minimal JSON:API client and React hooks for fetching, updating, and caching remote data.
MIT License
149 stars 28 forks source link

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

Closed bhavesh1334 closed 1 year ago

bhavesh1334 commented 2 years ago

ss135

bhavesh1334 commented 2 years ago

ss135

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

aribouius commented 2 years ago

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'))