I am using the react-bootstrap Modal, Form and Button.
Desiring the functionality of clicking the button should open the modal with a form inside it. After filling out the form, one clicks a button (on the modal) and it validates the form data and posts it through a REST API.
I got far enough to figure out that my component split should be as follows:
A button component, a modal component and a form component.
What would be the correct way to structure these components in terms of props/state and placing the functions for validating the data? I am having trouble in understanding the child/parent relationship and when it's applicable
For basic pseudo code
Main Component:
ModalPopUp component:
Form Component:
Above are the basic superComponent which we have rendered in app/main entry file. And form || Modal Component. are the child component.
So in modal component I have called the same Form-component.
Here in Form-component input type handler, submit button is disabled from state.. with input string length we are handling its validation.
I hope it works for you.
Components:
App Component: This is going to be the top level component
Button Component (If its just a button can also be just a button): If this is just a button you can keep this has a just a button in
App component
, if you are willing to reuse this with some custom element place it in a component.Component Tree:
App Component will contain a state like showModal, we need to have a handler to set this value and this handler gets triggered when the button is clicked.
Form Modal:
Hope that helped!