Skip to content

Instantly share code, notes, and snippets.

@Prasanna-Poonacha
Last active October 25, 2020 17:39
Show Gist options
  • Save Prasanna-Poonacha/5699954c0dd4ac20716c5160358a6108 to your computer and use it in GitHub Desktop.
Save Prasanna-Poonacha/5699954c0dd4ac20716c5160358a6108 to your computer and use it in GitHub Desktop.
class App extends Component {
state = {
users: [],
repos: [],
loading: false,
alert: null,
user: {},
};
searchUsers = async (text) => {
this.setState({
loading: true,
});
const res = await axios.get(
`https://api.github.com/search/users?q=${text}&client_id=${process.env.REACT_APP_GITHUB_CLIENT_ID}&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}`
);
this.setState({
users: res.data.items,
loading: false,
});
};
getUser = async (username) => {
this.setState({
loading: true,
});
const res = await axios.get(
`https://api.github.com/users/${username}?client_id=${process.env.REACT_APP_GITHUB_CLIENT_ID}&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}`
);
this.setState({
user: res.data,
loading: false,
});
};
getUserRepos = async (username) => {
this.setState({
loading: true,
});
const res = await axios.get(
`https://api.github.com/users/${username}/repos?per_page=10&sort=created:asc&client_id=${process.env.REACT_APP_GITHUB_CLIENT_ID}&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}`
);
this.setState({
repos: res.data,
loading: false,
});
};
clearUsers = () => {
this.setState({ loading: false, users: [] });
};
setAlert = (msg, type) => {
this.setState({ alert: { msg, type } });
setTimeout(() => this.setState({ alert: null }), 3000);
};
render() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment