Created
November 1, 2018 00:46
-
-
Save quisido/24c336eda2b2f41d57e44c443a490863 to your computer and use it in GitHub Desktop.
React Suspense with the Fetch API
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 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