Learning react so please bear with...
Below code works for me and allows me to set the valueOne as OneOneOne
import react from "React";
function LoadPage() {
const [valueOne, setvalueOne] = useState(GetValueOne);
function GetValueOne() {
return "OneOneOne";
}
}
The issue I am having is I need to make a call to the server to return the actual value of valueOne on page load... So I have changed to the following:
async function GetValueOne() {
let oneResult;
await axios.get(`${getBaseUrl()}/One/GetValueOfOne`).then((res) => {
oneResult = res.data;
});
return oneResult;
}
This is now not working as I have changed the function to async to wait for the axios.get request...Can I update the useState to match this?
If not is there another way to do this please?