Last active
March 15, 2018 19:41
-
-
Save CharlesMangwa/4f39461c9c4152c546ee14fd894c8180 to your computer and use it in GitHub Desktop.
React Data Fetching - Use case with/without`<ConnectedFetch>`
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, { Component } from 'react' | |
import { View, Text } from 'react-native' | |
import { Fetch } from 'react-data-fetching' | |
export default class Container extends Component { | |
render() { | |
return ( | |
<> | |
// Without <ConnectedFetch> | |
<Fetch | |
url="https://api.nyan.com/cats/meowssages" | |
headers={{ | |
'X-Nyan-Token': 'superNyan', | |
}} | |
> | |
{({ data }) => ( | |
<View> | |
<Text>You have {data.total} unread messages.</Text> | |
</View> | |
)} | |
</Fetch> | |
// With <ConnectedFetch> | |
<Fetch path="/cats/meowssages"> | |
{({ data, store }) => ( | |
<View> | |
<Text>Hello {store.user.firstName}!</Text> | |
<Text>You have {data.total} unread messages.</Text> | |
</View> | |
)} | |
</Fetch> | |
</> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment