Created
December 28, 2022 11:33
-
-
Save CodeNinja47/3c0011a112bc09ab5d365054214a6478 to your computer and use it in GitHub Desktop.
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, { useEffect, useState } from 'react'; | |
| import { HelloQuery } from './relay/graphql/query/Hello'; | |
| import { fetchQuery } from './relay/index'; | |
| // getting a test environment as props | |
| export default function Testing({ environment }) { | |
| // a react useState hook | |
| const [text, setText] = useState(''); | |
| const makeApiCall = () => { | |
| // Make the graphQL call by passing the test environment | |
| fetchQuery(HelloQuery, {}, environment).subscribe({ | |
| next: (data) => { | |
| // The HelloQuery will return a string, so we can set that to | |
| // our state object | |
| setText(data.hello); | |
| console.log(data.hello) | |
| }, | |
| error: (error) => { | |
| } | |
| }); | |
| } | |
| useEffect(() => { | |
| // Trigger the graphQL call | |
| makeApiCall(); | |
| }, []); | |
| return ( | |
| <div className="text-center"> | |
| <div>{text}</div> | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment