@axelhzf/react-apollo-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

React Apollo Hooks

React hooks to integrate with React Apollo

  • useApollo
  • useQuery
  • useMutation

Install

$ yarn add @axelhzf/react-apollo-hooks

Usage

import gql from 'graphql-tag';
import { useQuery } from '@axelhzf/react-apollo-hooks';

function Component() {
  const { loading, error, data } = useQuery<PokemonsQuery, PokemonsVariables>({ query });
  if (error) return <div>Error :(</div>;
  if (loading || !data) return <div>Loading...</div>;  
  return (
    <div>
      {data.pokemons.map(pokemon => (
        <div key={pokemon.id}>
          #{pokemon.number} {pokemon.name}
        </div>
      ))}
    </div>    
  ) 
}

const query = gql`
  query Pokemons {
    pokemons {
      id
      number
      name
    }
  } 
`

How to run examples

Clone the repository

$ git clone git@github.com:axelhzf/react-apollo-hooks.git
$ cd react-apollo-hooks

The examples use a graphql api that you need to run in local

$ npx @axelhzf/graphql-pokemon-server

Now, you can run the examples

cd examples/cra-graphql-code-generator
yarn
yarn start

License

MIT License © Axel Hernandez Ferrera

Readme

Keywords

none

Package Sidebar

Install

npm i @axelhzf/react-apollo-hooks

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

23.9 kB

Total Files

28

Last publish

Collaborators

  • axelhzf