I have a React state that has some objects in it.
I want to be able to clone the c: "value"
, in the initial state, before it gets overwritten by e.target.value
input value
The reason why im doing this is because I want to this stored value to be tha actual value if user leaves the input empty
StateObj = {
a: "one",
b: 2,
option: {
c: "value"
}
}
<InputComp
value={StateObj.option.c}
onBlur={(e) => {
if(e.target.value === ""){
props.onChange(["option", "c"], "cloned value")} //the initial value c: "value"
}
}}
onChange={(e) => props.onChange(["option", "c"], e.target.value)} //gets overwritten if user start typing
>