-
Describe the bug To Reproduce See https://codesandbox.io/s/stupefied-poitras-11y82?file=/src/App.js - and its fullscreen version - https://11y82.csb.app/ The issue is evident in the fullscreen version -
Expected Behavior Suggested solution(s) Desktop (please complete the following information):
Additional context However, in the interest of understanding this deeper, so @bluebill1049 if you have any insights, I'd love to know. I've also created a similar issue on the Chakra-UI repo - see chakra-ui/chakra-ui#784 |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 2 replies
-
Take a look this issue: #1709 (comment) |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 I'm not sure which part of that example I should use. Are you recommending using |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 Thanks, I am looking at that specific CSB, but I'm finding it hard to understand where the solution lies. If you mean the Modal should have its own form, then in my case, it already does. I don't see much else of a difference in terms of what that and my examples are doing. |
Beta Was this translation helpful? Give feedback.
-
Your codesandbox has only had a text: 'test'. The problem is when form sit in a modal, you need to save the form values before close the modal, as inputs get unmount will result |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 Right, although my issue happens before I close the modal. If you run the linked app (https://11y82.csb.app/), you'll notice that the modal, on submit (it doesn't close/unmount at all), exhibits this behavior. I'll list down the steps to clearly see the issue —
What you see in step 6 is the problem. The modal hasn't closed/unmounted at any point between steps 2 - 6. |
Beta Was this translation helpful? Give feedback.
-
Can you do a version without the |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 Thanks a lot for helping! I built one without a |
Beta Was this translation helpful? Give feedback.
-
Try one without |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 You were right! Removing the |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 Do you have any ideas around how to solve this? Is preventing a remount the only solution, or is there something I can do with state/context to fix this from outside the library? |
Beta Was this translation helpful? Give feedback.
-
I don't have control over how they render an input, you may have to check at their repo for a solution. I would look at the solution to show error without using that wrapper for now. |
Beta Was this translation helpful? Give feedback.
-
The issue happened because the The fixed form can be found here - https://codesandbox.io/s/hook-form-gp-discussion-xl2qb?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
The issue happened because the
<EditModal>
component is created as a function inside the<App>
component & the hooks local to the App component are used inside EditModal. This is an antipattern in React & can be solved by moving EditModal outside of the App component & passing the required values as props.The fixed form can be found here - https://codesandbox.io/s/hook-form-gp-discussion-xl2qb?file=/src/App.js