🐛 fix(parameterComponent): fix type error in useState declaration for dictArr variable

🐛 fix(parameterComponent): fix logic error in onChange handler to update dictArr state when there are duplicate keys in the array
 feat(parameterComponent): add type annotation to onChange handler parameter to improve code clarity
This commit is contained in:
Cristhian Zanforlin Lousa 2023-08-31 10:36:49 -03:00
commit fadd28802d

View file

@ -103,7 +103,7 @@ export default function ParameterComponent({
key5: "value5",
key6: "value6",
} as {});
const [dictArr, setDictArr] = useState([]);
const [dictArr, setDictArr] = useState([] as string[]);
useEffect(() => {
setDictArr(convertObjToArray(dict));
@ -231,10 +231,14 @@ export default function ParameterComponent({
editNode={false}
value={dictArr}
duplicateKey={errorDuplicateKey}
onChange={(newValue) => {
onChange={(newValue: string[]) => {
setErrorDuplicateKey(hasDuplicateKeys(newValue));
if(hasDuplicateKeys(newValue)) return;
setDict(convertArrayToObj(newValue));
if(hasDuplicateKeys(newValue)){
setDictArr(newValue);
}
else{
setDict(convertArrayToObj(newValue));
}
}}
/>
</div>