Last active
March 15, 2018 19:41
-
-
Save CharlesMangwa/12f56344649394557e1bdb13c8b199e2 to your computer and use it in GitHub Desktop.
React Data Fetching - `requestToApi` use case
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 { requestToApi } from 'react-data-fetching' | |
// Just here for better understanding | |
import { ChatFeed } from './components' | |
export default class Chat extends Component { | |
state = { messages: null } | |
async componentDidMount() { | |
const apiResponse = await requestToApi({ | |
path: 'https://api.nyan.com/openChat', | |
method: 'GET', | |
params: { | |
start: 0, | |
limit: 100 | |
} | |
}) | |
if (apiResponse.isOK) | |
this.setState(() => ({ messages: apiResponse.result })) | |
} | |
render() { | |
<ChatFeed data={this.state.messages} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment