Created
August 22, 2018 18:00
-
-
Save lucasferreira/b293bed8ffb9f304aef126e10c758e93 to your computer and use it in GitHub Desktop.
React Async Fetcher Demo #1
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 from "react"; | |
import AsyncFetcher from "react-async-fetcher"; | |
const MyIpWidget = () => ( | |
<AsyncFetcher url="https://ipapi.co/json/"> | |
{({ isLoading, error, data }) => { | |
// some loading state... | |
if (isLoading) { | |
return <p>Loading data...</p>; | |
} | |
// if has any error in your request | |
if (error) { | |
return ( | |
<p> | |
<strong>Error:</strong> {error} | |
</p> | |
); | |
} | |
// if reach here your request was successful | |
return ( | |
<p> | |
<strong>My IP:</strong> {data.ip} <br /> | |
<strong>Location:</strong> {data.city} / {data.region} | |
</p> | |
); | |
}} | |
</AsyncFetcher> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Imagem demos:

