GithubHelp home page GithubHelp logo

userData? about classsed-graphql-mern-apollo HOT 10 OPEN

hidjou avatar hidjou commented on July 17, 2024
userData?

from classsed-graphql-mern-apollo.

Comments (10)

cannicombustiva avatar cannicombustiva commented on July 17, 2024 4

I solved the problem avoiding destructuring:
const { loading, data } = useQuery(FETCH_POSTS_QUERY);

and then:
<Grid.Row> {loading ? ( <h1>Loading Posts...</h1> ) : ( data.getPosts.map(post => ( <Grid.Column key={post.id}> <PostCard post={post} /> </Grid.Column> )) )} </Grid.Row>

if we get data from destructuring at the beginning of the component, it' s like to write something like:
const allQuery = useQuery(); const loading = allQuery.loading; const posts = allQuery.data.getPosts.posts;

Now what do we get if 'data' in the last line is undefined? getPosts of undefined;

from classsed-graphql-mern-apollo.

daksharajkamal avatar daksharajkamal commented on July 17, 2024 1

Just create a variable and fetch that data in that variable and I'll solve your error.

function Home() {
let posts = "";
const { loading, data } = useQuery(FETCH_POSTS_QUERY);
if (data) {
posts = data.getPosts;
}
return (

<Grid.Row className="page__title">

Recent Posts


</Grid.Row>
<Grid.Row>
{loading ? (

Loading...


) : (
posts &&
posts.map((post) => (
<Grid.Column key={post.id} style={{ marginBottom: 20 }}>

</Grid.Column>
))
)}
</Grid.Row>

);
}

from classsed-graphql-mern-apollo.

jhaji2911 avatar jhaji2911 commented on July 17, 2024 1

to solve this I think you'll have to pass Home() an empty object as an argument and then assign it to the destructured data :
function Home(arg = {}) {

const {user} = useContext(AuthContext);
 const {loading, data:{getPosts : posts}=arg} = useQuery(FETCH_QUERY);

from classsed-graphql-mern-apollo.

vincedesigns avatar vincedesigns commented on July 17, 2024

error
Please help!

from classsed-graphql-mern-apollo.

lacykerel avatar lacykerel commented on July 17, 2024

Hi Vince I eventually figured out how to resolve my issue. I would check to make sure posts is available in the data object that you're destructuring

from classsed-graphql-mern-apollo.

michaelpaulcuccia avatar michaelpaulcuccia commented on July 17, 2024

I am at this juncture - TypeError: Cannot read property 'getPosts' of undefined
and really have no idea what or why this is happening since I am following a tutorial to LEARN how to do this.
Any help would be appreciated.

from classsed-graphql-mern-apollo.

kholub1989 avatar kholub1989 commented on July 17, 2024

Same problem - TypeError: Cannot read property 'getPosts' of undefined

from classsed-graphql-mern-apollo.

kholub1989 avatar kholub1989 commented on July 17, 2024

Finally, I got it.

The problem with TypeError: Cannot read property 'getPosts' of undefined
is in the CLIENT side dependencies with the new version "@apollo/react-hooks": "^4.0.0", somehow it returns first undefined and after an Object.
The solution is using the oldest version "@apollo/react-hooks": "0.1.0-beta.7", or using @apollo/client.

from classsed-graphql-mern-apollo.

HSEKOL1025 avatar HSEKOL1025 commented on July 17, 2024

use {useEffect and useState } to solve this..

const {loading, data}= useQuery(FETCH_POSTS_QUERY);
const [Posts, setPosts] = useState([]);

useEffect(() => {
    if(loading === false && data){
        setPosts(data.getPosts);
        
    }
}, [loading, data])

all the posts are now in Posts array.

from classsed-graphql-mern-apollo.

louay007 avatar louay007 commented on July 17, 2024

how find solution i need it !!

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.