Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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