Created
July 3, 2019 16:09
-
-
Save jsmanifest/64d1e8c551869643ef2a555d7dd79671 to your computer and use it in GitHub Desktop.
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
const api = { | |
async getTotalFrogs() { | |
return { | |
data: { | |
result: [ | |
{ name: 'bob the frog', tongueWidth: 50, weight: 8 }, | |
{ name: 'joe the other frog', tongueWidth: 40, weight: 5 }, | |
{ name: 'kelly the last frog', tongueWidth: 20, weight: 2 }, | |
], | |
}, | |
} | |
}, | |
} | |
const getData = async ({ withTongues = false }) => { | |
try { | |
const response = await api.getTotalFrogs({ withTongues }) | |
return response.data.result | |
} catch (err) { | |
throw err | |
} | |
} | |
const DataList = (props) => { | |
const [items, setItems] = useState([]) | |
const [error, setError] = useState(null) | |
React.useEffect(() => { | |
getData({ withTongues: true }) | |
.then(setItems) | |
.catch(setError) | |
}, []) | |
return ( | |
<div> | |
{Array.isArray(items) && ( | |
<Header size="tiny" inverted> | |
{items.map(({ name, tongueWidth, weight }) => ( | |
<div style={{ margin: '25px 0' }}> | |
<div>Name: {name}</div> | |
<div>Width of their tongue: {tongueWidth}cm</div> | |
<div>Weight: {weight}lbs</div> | |
</div> | |
))} | |
</Header> | |
)} | |
{error && <Header>You received an error. Do you need a linter?</Header>} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment