I am getting following error when I testing hooks with async function;
Invariant Violation Objects are not valid as a React child (found: [object Promise]).
async function Test () {
const data = await fetch('https://jsonplaceholder.typicode.com/posts/42');
const json = await data.json();
const id = json.id;
return id;
}
...
function App() {
return (
<div className="App">
<h1>React Hooks Example</h1>
<Suspense fallback={<LoadingMessage />}>
<Test />
</Suspense>
</div>
);
}
https://codesandbox.io/s/4w2yzvyro7
How can I fix this error
See Question&Answers more detail:os