I am new to React and have a hard time understanding why when I call useEffect after I just set the new state on a variable, the new value is undefined. Can someone also explain why the second UseEffect hook is called twice. Is it because it's called on initial mount, and then called when it finally changes state from the first useEffect? How can I get it to fire only once val has a defined value that was set in the first useEffect?
import React from 'react';
import {useState, useEffect} from 'react'
export function App(props) {
const [val, setVal] = useState();
useEffect(() => {
setVal("hello");
},[]);
useEffect(() => {
console.log("value: ", val);
}, [val])
return (
<div className='App'>
</div>
);
}