🌍 react-native-fetch
Fetch API wrapped as a component for React Native
Table of Contents
Table of Contents
Install
Usage
Contribute
License
Install
$ npm install --save react-native-fetch
$ yarn add react-native-fetch
Usage
import Fetch from './fetch'
export default class Home extends Component {
_handleResponse = (res) => {
console.log(res)
res.text().then(console.log).catch(console.log)
}
_handleError = (error) => console.log(error)
render () {
return (
<View style={styles.container}>
<Fetch
url="https://jsonplaceholder.typicode.com"
onResponse={this._handleResponse}
onError={this._handleError}
/>
</View>
)
}
}
Properties
url
(String) - The request url. Required.onResponse
(Function) - Fired when response is received.onError
(Function) - Fired when error occurs during request.method
(String) - HTTP request method. Default: 'GET'body
(String, body types) - HTTP request body.headers
(Object, Headers)- HTTP request headers to send. Default: {}credentials
(String) - Authentication credentials mode. Default: 'omit'
Check out the fetch docs for more info.
Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the standard-readme specification.
License
Licensed under the MIT License.