Git Product home page Git Product logo

Comments (6)

jhaji2911 avatar jhaji2911 commented on July 20, 2024 2

@likwid23 @aindriu80
the best fix I figured out is just pass an empty object to the singlePost() function then assign the destructed data to it:

function SinglePost(props,args={}) {
const postId = props.match.params.postId;
const { user } = useContext(AuthContext);
const commentInputRef = useRef(null);
const [comment, setComment] = useState('');
const{ data:{getPost} = args } = useQuery(FETCH_POST, {
variables: {
postId
}
});

from classsed-graphql-mern-apollo.

reddymahendra52 avatar reddymahendra52 commented on July 20, 2024 2

@likwid23 @aindriu80
the best fix I figured out is just pass an empty object to the singlePost() function then assign the destructed data to it:

function SinglePost(props,args={}) {
const postId = props.match.params.postId;
const { user } = useContext(AuthContext);
const commentInputRef = useRef(null);
const [comment, setComment] = useState('');
const{ data:{getPost} = args } = useQuery(FETCH_POST, {
variables: {
postId
}
});

Thank you so much for this solution!! working fine for me.

from classsed-graphql-mern-apollo.

aindriu80 avatar aindriu80 commented on July 20, 2024

As answered in the other question:

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

....

let postMarkup;
if (!thisPost) {
postMarkup =

Loading Post...

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

Works but gets stuck on Loading...

from classsed-graphql-mern-apollo.

dramanesd avatar dramanesd commented on July 20, 2024

@aindriu80
you have to return only datalike this:
const { data } = useQuery(FETCH_POST_QUERY, {
variables: {
postId,
},
});

from classsed-graphql-mern-apollo.

Ozkilic avatar Ozkilic commented on July 20, 2024

...
const { loading, data } = useQuery(FETCH_POST, {
variables: {
postId,
},
})

let getPost
if (!loading) {
getPost = data.getPost
}

...

from classsed-graphql-mern-apollo.

nikchhetri avatar nikchhetri commented on July 20, 2024

I did this and it worked without any error

const postId = props.match.params.postId
const { user } = useContext(AuthContext)
const { loading, data} = useQuery(FETCH_POST_QUERY, {
variables: {postId}
}
)
if (loading){return (

Loading

)}; //this is where i added a line
const {id,
body,
createdAt,
username,
comments,
likes,
likeCount,
commentCount
} = data.getPost
let postMarkup

and then just define postMarkup and continue like he does.

from classsed-graphql-mern-apollo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.