How to use the graphql-hooks.useQuery function in graphql-hooks

To help you get started, weโ€™ve selected a few graphql-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nearform / graphql-hooks / examples / fastify-ssr / src / app / pages / HomePage.js View on Github external
function HomePage() {
  const [name, setName] = React.useState('')
  const { loading, data, error, refetch: refetchUsers } = useQuery(
    HOMEPAGE_QUERY
  )
  const [createUser] = useMutation(CREATE_USER_MUTATION)

  const [getFirstUser, { data: firstUserData }] = useManualQuery(
    GET_FIRST_USER_QUERY,
    {
      fetchOptionsOverrides: {
        method: 'GET'
      }
    }
  )

  async function createNewUser() {
    await createUser({ variables: { name } })
    setName('')
github zeit / next.js / examples / with-graphql-hooks / components / post-list.js View on Github external
export default function PostList() {
  const [skip, setSkip] = useState(0)
  const { loading, error, data, refetch } = useQuery(allPostsQuery, {
    variables: { skip, first: 10 },
    updateData: (prevResult, result) => ({
      ...result,
      allPosts: [...prevResult.allPosts, ...result.allPosts],
    }),
  })

  if (error) return 
  if (!data) return <div>Loading</div>

  const { allPosts, _allPostsMeta } = data

  const areMorePosts = allPosts.length &lt; _allPostsMeta.count
  return (
github datenguide / datenguide / src / pages / region / baden-wuerttemberg.js View on Github external
const RegionBadenWuerttemberg = () =&gt; {
  const classes = useStyles()
  const { loading, error, data } = useQuery(query, {
    variables: { id }
  })

  if (error) return <div>Error loading posts.</div>
  if (loading) return <div>Loading</div>

  const { WAHL09 } = data.region

  return (
    
      
        
          <h1>{name}</h1>
          <p>
            Baden-Wรผrttemberg ist nach Bayern und Nordrhein-Westfalen das
            drittgrรถรŸte Bundesland Deutschlands, sowohl bei der Flรคche als auch</p>
github nearform / graphql-hooks / examples / typescript / src / App.tsx View on Github external
function Posts() {
  const { loading, error, data, refetch } = useQuery(allPostsQuery)

  return (
    &lt;&gt;
      <h2>Add post</h2>
      
      <h2>Posts</h2>
      <button> refetch()}&gt;Reload</button>
      
    
  )
}
github ShadOoW / web-starter-kit / src / components / graphql-demo / graphqlDemo.js View on Github external
function GraphqlDemo() {
  const [page, setPage] = useState(1);
  const [searchInputValue, setSearchInputValue] = useState('');

  useEffect(() =&gt; setPage(1), [searchInputValue]);

  const { loading, error, data } = useQuery(GET_CHARACTERS, {
    variables: { name: searchInputValue, page },
    notifyOnNetworkStatusChange: true,
  });

  return (
    
      
        <input placeholder="Filter by name (ex: Rick, Robot)"> setSearchInputValue(value)}
          isLoading={loading}
        /&gt;
      

      {error &amp;&amp; (
github nearform / graphql-hooks / examples / create-react-app / src / components / Posts.js View on Github external
export default function Posts() {
  const { loading, data, error, refetch } = useQuery(allPostsQuery)

  return (
    &lt;&gt;
      <h3>Add post</h3>
      
      <h3>Posts</h3>
      
    
  )
}
github datenguide / datenguide / src / pages / region / [slug].js View on Github external
const Region = ({ slug, id, name }) =&gt; {
  const { loading, error, data } = useQuery(allPostsQuery, {
    variables: { id }
  })

  if (error) return <div>Error loading posts.</div>
  if (loading) return <div>Loading</div>

  const { WAHL09 } = data.region

  return (
    
      <h1>
        {name} / {id} / {slug}
      </h1>

      <h3>Election results (2017)</h3>

graphql-hooks

Graphql Hooks

Apache-2.0
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis