When I change the content of input field and log it using console.log(e.target.value) then updated value gets logged but when i use setContent(e.target.value) it is setting the content's value to previous value of input
const Search=()=>{
const[content,setContent]=useState([]);
const[todos,setTodos]=useState([]);
useEffect(() =>{
document.title="Search";
},[])
//searching in database
const searchDatabase=(content)=>{
axios.get(`${base_url}/search/${content}`).then(
(response)=>{
setTodos(response.data);
},
()=>{
console.log("Database Down")
}
)
}
return (
<div>
<Row>
<Form className="form-inline mt-2 mb-4">
<FaSearch/>
<Input id="searchBox" className="ml-3" type="text"
onChange={(e)=>{
console.log("current value: "+e.target.value);
setContent(e.target.value);
console.log("content value: "+content);
searchDatabase(content)
}}
/>
</Form>
</Row>
</div>
)
}
Thanks for help..