const initData = {
name: "",
class: ""
}
const [currentStudent, setCurrentStudent] = useState({});
useEffect(() => {
// My example code to setState
setCurrentStudent(exampleData)
//The result of currentStudent is {name: "Alex", class: "4"}
}, []);
const [formData, setFormData] = useState({ condition ? currentStudent : initData });
It's mean if true formData has result is currentStudent {name: "Alex", class: "4"}, if false will initData state.
But result when I tried the code above is an emty object like this {}.
How can I set formData state = currentStudent ({name: "Alex", class: "4"})