Created
February 13, 2018 16:52
-
-
Save diego3g/998df424b8e8aa0bafd5a5d8ac8c255c to your computer and use it in GitHub Desktop.
This file contains 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
export default class App extends Component { | |
state = { | |
data: [], | |
page: 1, | |
loading: false, | |
}; | |
componentDidMount() { | |
this.loadRepositories(); | |
} | |
loadRepositories = async () => { | |
if (this.state.loading) return; | |
const { page } = this.state; | |
this.setState({ loading: true }); | |
const response = await fetch(`${baseURL}/search/repositories?q=${searchTerm}&per_page=${perPage}&page=${page}`); | |
const repositories = await response.json(); | |
this.setState({ | |
data: [ ...this.state.data, ...repositories.items ], | |
page: page + 1, | |
loading: false, | |
}); | |
} | |
// Resto da classe | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment