Back to Urql

or

packages/preact-urql/README.md

1.8.21.3 KB
Original Source
<div align="center"> <a href="https://www.npmjs.com/package/@urql/preact"> </a> <a href="https://bundlephobia.com/result?p=@urql/preact"> </a> <a href="https://github.com/urql-graphql/urql/discussions"> </a> </div>

Installation

sh
yarn add @urql/preact urql graphql
# or
npm install --save @urql/preact urql graphql

Usage

The usage is a 1:1 mapping of the React usage found here

small example:

jsx
import { createClient, cacheExchange, fetchExchange, Provider, useQuery } from '@urql/preact';

const client = createClient({
  url: 'https://myHost/graphql',
  exchanges: [cacheExchange, fetchExchange],
});

const App = () => (
  <Provider value={client}>
    <Dogs />
  </Provider>
);

const Dogs = () => {
  const [result] = useQuery({
    query: `{ dogs { id name } }`,
  });

  if (result.fetching) return <p>Loading...</p>;
  if (result.error) return <p>Oh no...</p>;

  return result.data.dogs.map(dog => <p>{dog.name} is a good boy!</p>);
};