In this tutorial, we are going to build a modal in React. Below is a demo of it.
Prerequisites
These are the prerequisites required t...
For further actions, you may consider blocking this person and/or reporting abuse
Hi, nice article.
We prefer to use Modal components wrapped in a component which use ReactDOM.portal (comes with 16v) for better UI mechanism. Modals and popups are looks familiar but functionality. For example; you have a form in popup, and you have to show a modal if itβs successfully posted or failed badly. Modals needs to be above popup. Weβve created 2 roots like app-root; popup-root and modal-root in a large-scaled application. By this way render methods stay clean and UI flows properly without trading CSS hacks, thanks to DOM order.
Thank you for this article (:
Thanks for the comment, this is the first time I am hearing about ReactDOM.portal, I will go and check it out π.
(Y) basically it allows you to use components outside of your app-root.
See you (:
Nice write-up! But perhaps not the best to put the children in a
<p>
? Good article. :)Noted...thanks π
Hi,
why use two functions (openModalHandler and closeModalHandler) when you can simply have:
toggleModal = () => {
this.setState(prevState=> {
isShowing: !prevState.isShowing
})
}
and also in this kind of situations wouldn't it be more optimal to use functional component with react hooks instead of class?
Thanks for the suggestion on using the conditional operator. Also, at the time this post was published, React Hooks didn't exist.
Hi, if i want to add Function on Continue button how can i do that?
basically i want to display a dropdown menu as i click continue button
Hello
Add this below the closeModalHandler
and then change the continue button to this
My Page is very big and there is various open modal button in the center ,bottom and top . but the modal is open in top only... i want it scrollable as per where my button is.... like if i scroll down then this modal also go with it,... how can i do it??? @Atauba Prince