Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wait for Query result #33

Open
landorid opened this issue Dec 26, 2018 · 2 comments
Open

How to wait for Query result #33

landorid opened this issue Dec 26, 2018 · 2 comments

Comments

@landorid
Copy link

I would like to use React Adopt with Formik and Apollo Client. I am getting initial form data in getUser but first time I am getting empty data object with loading flag, and when the result came back from server, loading flag turn to false and I get the result. Using following snippet, Formik always initialised with empty array, because rendering Formik doesn't wait for loading=false.

const Composed = adopt({
  getUser: ({ render }) => <Query query={CURRENT_USER_PROFILE_QUERY} children={render}/>,
  updateUser: ({ render }) => <Mutation mutation={CURRENT_USER_UPDATE_MUTATION} 
                                            children={render}/>,
  form: ({ render, updateUser, getUser }) =>
        <Formik initialValues={{ ...formDefaultValue, ...getUser.data.me }} children={render} />,
    });

Without React Adopt my code looks like this:

<Query query={CURRENT_USER_PROFILE_QUERY}>
  {({ loading, error, data }) => {
     if (!loading) return (
        <Formik initialValues={{ ...formDefaultValue, ...data.me }}>

How can I achieve it with React Adopt?

@morexlt
Copy link

morexlt commented Feb 4, 2019

If you dont use mapProps, then you can use getUser.loading or getUser.error.

@manonthemat
Copy link

If you dont use mapProps, then you can use getUser.loading or getUser.error.

But apparently not within in the render function where Composed is used. I also did not find any documentation that would support this claim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants