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

getPost From DAta Undefined #12

Closed
ArielPenna opened this issue Nov 2, 2020 · 9 comments
Closed

getPost From DAta Undefined #12

ArielPenna opened this issue Nov 2, 2020 · 9 comments

Comments

@ArielPenna
Copy link

I think the problem might be in the destructoring? according to the error "data " is undefined

image

@asinorum
Copy link

asinorum commented Nov 4, 2020

I didnt have the exact same error , but maybe it helps, This what ended worked for me for some reason
const {data ={}} = useQuery(FETCH_POST_QUERY, { variables: { postId } })

Also replacing getPost for data.getPost in the rest of the code

@likwid23
Copy link

likwid23 commented Nov 5, 2020

@asinorum That got rid of the error but now it gets stuck on Loading....

it never gets past the (!data.getPost)

@ArielPenna
Copy link
Author

same to me,

@ArielPenna
Copy link
Author

So annoying, i've tried everithing tha crossed mi mind, but it stills throw me the data undefined error

@mariusflorescu
Copy link

mariusflorescu commented Nov 6, 2020

Hello @ArielPenna 🚀, have you tried to do the following changes:

From:

const {data:{getPost}} = useQuery(FETCH_POST_QUERY,{
    variables: {
      postId
    }
  })

To:

const {data={}} = useQuery(FETCH_POST_QUERY,{
    variables: {
      postId
    }
  });
const thisPost = data.getPost;
  • change everywhere you see getPost to thisPost. (in the if statement and in the first instruction of the else).

Hope that helped you, let me know if it works!

@likwid23
Copy link

likwid23 commented Nov 6, 2020

@mariusflorescu if I remove (!thisPost) I get:

TypeError: Cannot destructure property 'id' of 'thisPost' as it is undefined.

if (thisPost) {
25 | postMarkup =

Loading post..


26 | } else {

27 | const { id, body, createdAt, username, likes, likesCount, comments, commentCount} = thisPost;
| ^ 28 |
29 | postMarkup = (
30 |

Any ideas are appreciated

@ArielPenna
Copy link
Author

Thanks @mariusflorescu this just work fine, i've tried it before I think, but didn't work.
Thanks a lot!!

@ArielPenna
Copy link
Author

@likwid23 try like this, it's working for me

let postMarkup;
if (!thisPost) {
postMarkup =

Loading post..

;
} else {
const { id, body, createdAt, username, comments, likes, likeCount, commentCount } = thisPost;

@mariusflorescu
Copy link

@ArielPenna I'm glad it worked.
You can mark the issue as closed 😁!

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

4 participants