my handleOnChangeNavBar function takes a parameter which is a title. The function is called each time a new button is clicked in my navigationbar.
It then goes througth the files and see if any of the files matches the title. If it does, then setValue("").
every time I select a new title I want it to reset value to "". This works fine, unless there is a array in value from previous state.
It is not all files that have an input_type as array, so if the input_type is "text" is works fine and value is set to ""
for example if value looks like this:
{
title: "test",
emails: [
"email@email.dk",
"e@e.dd"
]
}
then after the title changes and activates the handleOnChangeNavBar function, value will not remove the array, so when i need it to clear up it just result in value looking like this:
{
emails: [
"email@email.dk",
"e@e.dd"
]
}
and i dont know why..
IF title changes i would always want i to clear out and setValue("")
This is the handleOnChangeNavBar function:
function handleOnChangeNavBar(title) {
console.log(title)
Object.keys(files).forEach((key) => {
if (files[key].title === title) {
setValue("")
{
Object.values(files[key].Input).map((form) => {
if (form.input_type === "array") {
if (!(Object.keys(value).includes(form.name))) {
setValue({ ...value, [form.name]: [""] })
}
}
}
)
}
setData(files[key]);
setInput(files[key].Input);
}
});
setChoice(title);
setSchema("");
};