here is my code
import React, { useState } from "react";
function Search(props) {
const [user, setUser] = useState("tab21");
const selectUser = (enteredUser) => {
setUser(enteredUser === "" ? "tab21" : enteredUser);
props.getuser(user);
console.log("user in search", user);
};
return (
<div className="bg-black w-full p-2 flex px-4 space-x-3">
<input
type="text"
name="user"
id="user"
placeholder="tab21"
className="p-1 w-4/5 rounded-md"
required
/>
<button
type="submit"
className="p-1 w-1/5 bg-green-500 rounded-md text-white hover:bg-emerald-500"
onClick={() =>
selectUser(document.getElementById("user").value)
}
>
Search
</button>
</div>
);
}
export default Search;
i do understand that it is not able to render by that time but how to get it to wait till it updates the state.
I tried to find options on the internet and saw many people have this problem but i am not able to collect and apply the same here.