-1
I’m having trouble checking if the value is undefinded. I need to make a if for this validation, follow my code:
My interface:
interface IModalContatos {
dados: IContatos | undefined;
onSave:(dados: IContatos) => void;
onClose:() => void;
}
Man state (state):
const [contatoAtualizado,setContatoAtualizado]=useState<IContatos>(dados as IContatos);
Validation:
useEffect(() => {
if (dados === undefined) {
}
setContatoAtualizado(dados as IContatos)
}, [dados]);
I believe you wanted to return the data as Undefined when there is no
iContatos, in this case is a double pipe:dados: IContatos || undefined;– Ivan Ferrer
You can also return this, it will result in boolean: true / false:
return (!!IContatos);– Ivan Ferrer
I don’t quite understand what you want to do. Could you try [Edit] the question to clarify what your goal is? You just want to update the state if
dadosis different fromundefined? Then it wouldn’t be enough to put thesetContatoAtualizado(dados)within theif, also changing it toif (dados !== undefined) { ... }?– Luiz Felipe