add: prevent empty input to set and call API

This commit is contained in:
sushant dhimal 2023-03-07 16:39:31 +05:45
parent 4eaf4372b9
commit 47578f9cb0
1 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,12 @@ function App() {
const handleSubmit = (e) => {
e.preventDefault();
if (inputPrompt.trim() !== "") {
setChatLog([...chatLog, { chatPrompt: inputPrompt }]);
callAPI();
}
async function callAPI() {
try {
const response = await fetch("https://talk-bot.onrender.com/", {
@ -42,7 +47,7 @@ function App() {
console.log(err);
}
}
callAPI();
setInputPrompt("");
};