Skip to content

Instantly share code, notes, and snippets.

@lucasferreira
Created August 22, 2018 18:00
Show Gist options
  • Save lucasferreira/b293bed8ffb9f304aef126e10c758e93 to your computer and use it in GitHub Desktop.
Save lucasferreira/b293bed8ffb9f304aef126e10c758e93 to your computer and use it in GitHub Desktop.
React Async Fetcher Demo #1
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>
);
@lucasferreira
Copy link
Author

Imagem demos:
react-async-fetcher-demo1
react-async-fetcher-demo2

@lucasferreira
Copy link
Author

Logo
logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment