react apollo mutations status

provide loading and error properties to apollo mutations

1
0
JavaScript

react-apollo-mutations-status

npm
License: BSD-3-Clause
standard-readme compliant

David
David

Adds loading and error properties to apollo mutations. Based on https://gist.github.com/ctavan/7219a3eca42f96a5c5f755319690bda7

Table of Contents

Install

yarn add --dev react-apollo-mutations-status

Usage

import { graphql, compose } from 'react-apollo';
import mutationsStatus from 'react-apollo-mutations-status';
import React from 'react';

const Register = ({ register }) => (
  <form onSubmit={register.exec}>
    {register.loading && <div>Loading…</div>}
    {register.error && <div>{register.error}</div>}
    <button type="submit" />
  </form>
);

export default compose(
  graphql(GQL_MUTATION, { name: 'register' }),
  mutationsStatus(['register'])
)(Register);
import { graphql, compose } from 'react-apollo';
import mutationsStatus from 'react-apollo-mutations-status';
import React from 'react';

const Register = ({ mutate, loading, error }) => (
  <form onSubmit={mutate.exec}>
    {loading && <div>Loading…</div>}
    {error && <div>{error}</div>}
    <button type="submit" />
  </form>
);

export default compose(
  graphql(GQL_MUTATION),
  mutationsStatus()
)(Register);

License

BSD-3-Clause