Created
February 24, 2020 13:58
-
-
Save pratikagashe/71735d40fdd025a54381259734ab80be to your computer and use it in GitHub Desktop.
client Users.tsx graphql query: postgraphile demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react' | |
import { useGetUsersQuery, User } from '../generated/graphql' | |
const Users: React.FC = () => { | |
const [users, setUsers] = useState() | |
const { data, error, loading } = useGetUsersQuery() | |
useEffect(() => { | |
if (data) { | |
if (data && data.allUsers && data.allUsers.nodes) { | |
setUsers(data.allUsers.nodes) | |
} | |
} | |
if (error) { | |
console.log(error) | |
} | |
if (loading) { | |
console.log(loading) | |
} | |
}, [data, error, loading]) | |
return ( | |
<> | |
<h2>Hello users,</h2> | |
{users && | |
users.length > 0 && | |
users.map((user: User, index: number) => ( | |
<p key={`user_${index}`}>{user.name}</p> | |
))} | |
</> | |
) | |
} | |
export default Users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import { useGetUsersQuery, User } from '../generated/graphql'
it should be
'./generated/graphql'