Hi. I'm trying reset a form according to the example on https://www.telerik.com/kendo-react-ui/components/form/advanced-scenarios/ , as shown under "Resetting the Form Initial State". However, it does not work form me if I want to reset it with an object with the same data.
My scenario is that a user loads a form with initial data, fills in the form, submits the form. After the submit, we would like the form to revert to its original state (initial data). This does not happen as JSON.stringify produces the same key. I sorted it by adding an extra space into one property but I am sure there must be a better way to achieve this.
// initial data
const [user, setUser] = React.useState({
firstName: "John",
lastName: "Smith",
email: "John.Smith@email.com",
});
// data to reset
const loadNewUser = () => {
setUser({
firstName: "John",
lastName: "Smith",
email: "John.Smith@email.com",
});
};
My scenario is that a user loads a form with initial data, fills in the form, submits the form. After the submit, we would like the form to revert to its original state (initial data). This does not happen as JSON.stringify produces the same key. I sorted it by adding an extra space into one property but I am sure there must be a better way to achieve this.
// initial data
const [user, setUser] = React.useState({
firstName: "John",
lastName: "Smith",
email: "John.Smith@email.com",
});
// data to reset
const loadNewUser = () => {
setUser({
firstName: "John",
lastName: "Smith",
email: "John.Smith@email.com",
});
};