Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

react-query.md

37 lines867 Bytes

The react-query package offers a 1st-class API for using TanStack Query via React. However, all of the primitives you receive from these hooks are core APIs that are shared across all of the TanStack Adapters including the Query Client, query results, query subscriptions, etc.

Example

import { QueryClient, useQuery } from '@tanstack/react-query'

const queryClient = new QueryClient()

function Example() {
  const query = useQuery('todos', fetchTodos)

  return (
    <div>
      {query.isLoading
        ? 'Loading...'
        : query.isError
        ? 'Error!'
        : query.data
        ? query.data.map((todo) => <div key={todo.id}>{todo.title}</div>)
        : null}
    </div>
  )
}

function App () {
  return (
    <QueryClientProvider value={queryClient}>
      <Example />
    </QueryClientProvider>
  )
}