0

I have a const in ReactJS which is an object and I want to loops over it to set all values to undefined to reset the state and re-render the component to get a clean form

const [newPayee, setNewPayee] = useState<INewPayee>(() => {
    return {
        appUserId: userInfo.id,
        fullName: '',
        phoneNumber: '',
        email: '',
        streetAddress: '',
        city: '',
        postalCode: '',
        stateId: 0,
        bankId: 0,
        bankAccountNo: '',
        bankInstitutionNo: '',
        transitNo: '',
        note: ''
    }
});

1 Answer 1

0
for (const [key, value] of Object.entries(newPayee)) {
    setNewPayee(prev => ({ ...prev, [key]: undefined }));
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.