Skip to content

Instantly share code, notes, and snippets.

@ricklopez
Last active August 12, 2020 15:47
Show Gist options
  • Save ricklopez/8dc1a40a0168cd93f3cb554e138ee4c2 to your computer and use it in GitHub Desktop.
Save ricklopez/8dc1a40a0168cd93f3cb554e138ee4c2 to your computer and use it in GitHub Desktop.
handleUser = (e) => {
e.preventDefault();
const user = e.target['user-input'].value;
fetch(`${config.API_ENDPOINT}/reviews/${user}`)
.then((res) => {
if (!res.ok) return res.json().then((e) => Promise.reject(e));
return res.json();
})
.then((data) => {
if(data.length < 1){
this.setState({
reviews: [
{user_name: '', title: "No Results", author: '', content: ''},
],
});
}
else{
this.setState({
reviews: [
...data,
],
});
}
})
.catch((error) => {
console.error({ error });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment