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