I have a split date input (3 different inputs for DD/MM/YYYY) - I've been having some console issues whereby "A component is changing an uncontrolled input to be controlled - likely caused by value changing from undefined to defined."
Basically what I want to do is ensure that if a string value for dateInputValue
exists (in this format: "28-08-2022"), then we split it up and pre-populate the fields (this is working).
However, I want to make my code more robust by adding a check that if a string value like so doesn't exist in dateInputValue
and it's just an empty string, that the 3 inputs are populated by 3 empty strings ("").
Can anyone suggest an appropriate change to make this happen?
const [intialDay, initialMonth, initialYear] = dateInputValue.split("-");
const [day, setDay] = useState(intialDay);
const [month, setMonth] = useState(initialMonth);
const [year, setYear] = useState(initialYear);