I am using the react-formio package to generate a form dynamically.
I have generated a simple login-form using this link: https://codesandbox.io/s/cra-react-formio-iy8l
You can try to use the submission property of the component.
As per docs..
Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form.
So in this case you can control the component in a parent component.
Here submissionData
is a parent component state and the component initializes with the state from parent (Empty values initially).
Now, inside the onSubmit
handler you can try to reset the state and force a re-render.
onSubmit={() => {
// Reset submission data
setSubmissionData({});
};
}
Complete code would look like below.
export default () => {
const [submissionData, setSubmissionData] = useState({});
return (
Attached codesandbox link as comment.