Skip to content

Instantly share code, notes, and snippets.

@CodeNinja47
Created December 28, 2022 11:33
Show Gist options
  • Select an option

  • Save CodeNinja47/3c0011a112bc09ab5d365054214a6478 to your computer and use it in GitHub Desktop.

Select an option

Save CodeNinja47/3c0011a112bc09ab5d365054214a6478 to your computer and use it in GitHub Desktop.
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