Weird React Behaviour, lost on how to debug
Hey guys,
I've been losing hair over this and am a bit lost, hoping someone can help.
I have this modal component which I can call, await and get a value from:
I like this pattern, it allows me to show some UI conditionally typically during a validation process. Kind of like window.confirm, but with my own UI.
I am using it in my app here:
Finally, I mount my component:
2 Replies
Now, when I submit my form, and input is valid, my onsubmit function runs and I get to this line
And I am getting an error "Modal component not initialized"
Which is super weird. I am clearly rendering this modal in my jsx, its not conditional at all. Whats REALLY weird, is if just throw a button on the page with an onclick of showOptOutWarningModal(), it works perfectly. It seems to be not behaving correctly from inside the onSubmit function. I have tried making that function a useCallback with dependencies, no help. I am a bit lost on how to continue debugging this. Any input from some React wizards would be so helpful. Thankyou!
hi @Cody ,
I tried to reproduce your code, and it is weirdly working for me, though I skipped the useForm hook and had my own implementation of Modal element.
here's the link to the codesandbox, you can check it out
https://codesandbox.io/p/sandbox/g2k8gl
maybe the issue is in the different part of the app that you think
I don't know if you've already figured it out or no (judging from the time you've first posted), but let me know if there's any more things poping up