menu
up-caret
down-caret

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 馃殌

# General

General Apollo GraphQL discussions.

Trending conversations
馃憢 Welcome to the Apollo community!
@hwillson5d
What's up with the docs?
@boris-da-web-dev24d
How to use refresh tokens? Looking for a complete guide or repo for Apollo鈥
@stupid-sexy-jake15h
How do you guys handle authentication?
@lewix32d
We will be getting a new API for apollo-react using hooks soon?
@travers19d

How do I get the response data in the mutation HOC into the react component so that I can conditionally render UI based on the data? https://gist.github.com/caseysiebel/6a8491904c0c373d3953898cffca05ef#file-exp-js-L10

Apollo/General路 February 21, 2019 at 7:17pm

How do I get the response data in the mutation HOC into the react component so that I can conditionally render UI based on the data? https://gist.github.com/caseysiebel/6a8491904c0c373d3953898cffca05ef#file-exp-js-L10

February 21, 2019 at 7:17pm (Edited 1 month ago)

February 21, 2019 at 7:23pm

why not use Query HOC component and compose your query in such way so you can get the info you need?

  • reply
  • like

seems like you are doing the login, based on your gist. my approach is to have isLoggedIn = isLoggedIn() in default state, which checks the JWT and set's the stuff accordingly. then I use PrivateRoute HOC that takes care of the login, There i have Query component which always tells is the logged in status changed

  • reply
  • like

@woss I can't get the response data into the react component using the structure I have with mutate?

  • reply
  • like

you mean console.log('data', data); is null?

  • reply
  • like

i've never seen that approach :(

  • reply
  • like

I'm logging the data there, yes. But what I want to do is get that data object into the Login component props

  • reply
  • like

so i can conditionally display an error is the login was unsuccessful

  • reply
  • like

does that make sense?

  • reply
  • like

data is not null

  • reply
  • like

that could ereally save your day. if you know of Redux, that's similar.

  • reply
  • like

Man, that seems like a lot wire up.

  • reply
  • like

Feels like i should be able to just get that data into my react component

  • reply
  • like

:)

  • reply
  • like

Not sure exactly what you're trying to accomplish, but something like this should allow you to pass server-thrown errors down to your component:

  • reply
  • like

It looks like you're using formik so you'd probably want to leverage setFieldError in a nicer way, but I think pulling from your catch will be a better path to a nice UI

  • reply
  • like