provide loading and error properties to apollo mutations
Adds loading
and error
properties to apollo mutations. Based on https://gist.github.com/ctavan/7219a3eca42f96a5c5f755319690bda7
yarn add --dev react-apollo-mutations-status
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);
BSD-3-Clause