Skip to content

Instantly share code, notes, and snippets.

@quisido
Created November 1, 2018 00:46
Show Gist options
  • Save quisido/24c336eda2b2f41d57e44c443a490863 to your computer and use it in GitHub Desktop.
Save quisido/24c336eda2b2f41d57e44c443a490863 to your computer and use it in GitHub Desktop.
React Suspense with the Fetch API
import useFetch from 'fetch-suspense';
const MyComponent = () => {
// "Look! In the example! It's a fetch() request! It's a hook!"
// "No! It's kind of like both at the same time."
const serverResponse = useFetch('/path/to/api', { method: 'POST' });
// The return value is the body of the server's response.
return <div>{serverResponse}</div>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment