I just wrote a React HOC for getting mutation state like loading/error from props.
Apollo doesn’t provide loading props when doing Mutations for some reason, so we have to handle the loading state ourselves. Basically there are 3 ways:
use state in your component
use redux or other data flow libraries
use higher order component
Personally I like the 3rd way most because it’s clean and reusable.
Do you mean to return a Promise from GraphQL container and use it in the component? Such as <form onSubmit={e => submit(e).then(() => do somthing)}>? I think it still needs setState to handle the loading state change.
Your solution is the first way that I mentioned up there. It’s of course right. But the purpose of my package react-apollo-mutation-state is to make UI component stateless. all the logic of those requests can be done in a container.
I also thought about using Redux to achieve the same goal, but in most cases, one loading/submitting/saving state is only for a particular button. Saving one loading state in redux store for a single button is kinda too complicated and takes time to modify.
I’m not saying using HOC is the best way, but at least in some conditions, using HOC can be really comfortable.