Last active
August 12, 2020 15:47
-
-
Save ricklopez/8dc1a40a0168cd93f3cb554e138ee4c2 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
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