🌐
npm
npmjs.com › package › react-modal-hook
react-modal-hook - npm
July 22, 2022 - import React from "react"; import ReactDOM from "react-dom"; import { ModalProvider } from "react-modal-hook"; import App from "./App"; ReactDOM.render( <ModalProvider> <App /> </ModalProvider>, document.getElementById("root") ); Call useModal with the dialog component of your choice.
      » npm install react-modal-hook
    
Published   Jul 22, 2022
Version   3.0.2
Author   mpontus
🌐
npm
npmjs.com › package › react-hooks-use-modal
react-hooks-use-modal - npm
January 24, 2023 - A react hook which can open the modal with react-portal. Latest version: 3.3.1, last published: 3 years ago. Start using react-hooks-use-modal in your project by running `npm i react-hooks-use-modal`. There are no other projects in the npm registry ...
      » npm install react-hooks-use-modal
    
Published   Jan 24, 2023
Version   3.3.1
Author   shibe97
Discussions

useModal, a react hook for Modals/Dialogs/Lightboxes 🖼
Why do you need a hook? Wouldn’t a plain old portal do the job? More on reddit.com
🌐 r/reactjs
70
67
October 6, 2019
React hook: How to call Modal component from another component in react
I am trying to create a modal that I can reuse/call from multiple components. I want the modal to display in app.js but the button call is on another component. Once I am able to implement one, I c... More on stackoverflow.com
🌐 stackoverflow.com
How to use React’s new Context API to easily manage modals

Also found it useful for say managing the state of the hamburger button and drawer visibility

More on reddit.com
🌐 r/reactjs
15
128
January 23, 2017
How to open a modal from Flatlist Items?
Either have your data at the parent that is shared by the flat list and modal and set an item ID through a useState Hook that decides what is displayed on the modal, or try global state (e.g. redux, mobx, recoil) More on reddit.com
🌐 r/reactnative
5
1
October 1, 2020
🌐
GitHub
github.com › microcmsio › react-hooks-use-modal
GitHub - microcmsio/react-hooks-use-modal: This is a customizable modal with react-portal.
This is a react hook which can open the modal easily. import React, { useState, useCallback } from 'react'; import { createRoot } from 'react-dom/client'; import { useModal } from 'react-hooks-use-modal'; const App = () => { const [Modal, open, ...
Starred by 171 users
Forked by 22 users
Languages   TypeScript 80.2% | JavaScript 12.1% | CSS 7.2% | Shell 0.5% | TypeScript 80.2% | JavaScript 12.1% | CSS 7.2% | Shell 0.5%
🌐
Upmostly
upmostly.com › home › tutorials › modal components in react using custom hooks
How to Use Modal Components in React with Custom Hooks - Upmostly
October 28, 2021 - Therefore, we can use a Portal to mount our Modal component to the end of the document · .body element, rather than as a child of another component. To do this in the code above, we specify two arguments to the · createPortal function: the modal component we want to render and the location of where we want to append the component. Finally, let’s tie the custom React Modal Hook and the Modal component together.
🌐
GitHub
github.com › alexanderkhivrych › use-modal-hook
GitHub - alexanderkhivrych/use-modal-hook: 🚀 React hook for controlling modal components
import React, { memo } from "react"; import { useModal, ModalProvider } from "use-modal-hook"; import Modal from "react-modal"; // It can be any modal const MyModal = memo( ({ isOpen, onClose, title, description, closeBtnLabel }) => ( <Modal isOpen={isOpen} onRequestClose={onClose}> <h2>{title}</h2> <div>{description}</div> <button onClick={onClose}>{closeBtnLabel}</button> </Modal> ) ); const SomePage = memo(() => { const [showModal, hideModal] = useModal(MyModal, { title: "My Test Modal", description: "I Like React Hooks", closeBtnLabel: "Close" }); return ( <> <h1>Test Page</h1> <button onClick={showModal}>Show Modal</button> </> ); }); const App = () => ( <ModalProvider> <SomePage /> </ModalProvider> );
Starred by 69 users
Forked by 4 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
GitHub
github.com › mpontus › react-modal-hook
GitHub - mpontus/react-modal-hook: Syntactic sugar for handling modals using React Hooks
import React from "react"; import ReactDOM from "react-dom"; import { ModalProvider } from "react-modal-hook"; import App from "./App"; ReactDOM.render( <ModalProvider> <App /> </ModalProvider>, document.getElementById("root") ); Call useModal with the dialog component of your choice.
Starred by 254 users
Forked by 30 users
Languages   TypeScript 89.6% | JavaScript 6.4% | HTML 2.7% | CSS 1.3% | TypeScript 89.6% | JavaScript 6.4% | HTML 2.7% | CSS 1.3%
🌐
DEV Community
dev.to › viclafouch › build-a-complete-modal-component-with-react-hooks-2fk8
🔧 Build a complete Modal Component with React Hooks 🌈 - DEV Community
July 9, 2020 - Features like context work exactly the same regardless of whether the child is a portal, as the portal still exists in the React tree regardless of position in the DOM tree. ... Logically, it will be the parent component that will ask the modal to open. But how could we proceed? First of all, let's add a local state to our Modal component in order to know if the modal is open or not. useState allows us to create our state with a boolean value.
🌐
DEV Community
dev.to › alexandprivate › your-next-react-modal-with-your-own-usemodal-hook-context-api-3jg7
Your next React Modal with your own "useModal" Hook & Context API. - DEV Community
November 9, 2020 - Now let's write our Modal Component, and use the createPortal function, createPortal function expects two parameters, the first is the actual JSX and the second the DOM element where it will be rendered it. import React from "react"; import ReactDOM from "react-dom"; const Modal = () => { return ReactDOM.createPortal( <div className="fixed top-0 left-0 h-screen w-full flex items-center justify-center" style={{ background: "rgba(0,0,0,0.8)" }} > <div className="bg-white relative p-5 shadow-lg rounded flex flex-col items-start text-lg text-gray-800"> <button className="absolute top-0 right-0 -mt-12 font-bold self-end rounded-full bg-red-200 mb-3 bg-white text-red-700 w-8 h-8" onClick={() => {}} > &times; </button> <p>I am the Modal</p> </div> </div>, document.querySelector("#modal-root") ); }; export default Modal;
Find elsewhere
🌐
w3collective
w3collective.com › category: tutorial › building a react modal component using a custom hook
Building a React modal component using a custom Hook - w3collective
February 15, 2023 - Custom Hooks should always start with use so that you can quickly tell that it’s a re-usable Hook: import { useState } from 'react'; const useModal = () => { const [visible, setVisible] = useState(false); function toggle() { setVisible(!visible); } return {toggle, visible} }; export default useModal;Code language: JavaScript (javascript) Also in the /src folder create a new file called Modal.js for the modal component itself: import React from "react"; import ReactDOM from "react-dom"; const Modal = ({ visible, toggle }) => visible ?
🌐
GitHub
github.com › franlol › useModal
GitHub - franlol/useModal: React hook to wrap a component and show/hide it as a modal
With this hook, you can easily render components showing them as a modal: View components as a modals. Share logic to the modal component. Call toggle function to open/close the modal.
Starred by 7 users
Forked by 3 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
npm
npmjs.com › package › react-use-hook-modal
react-use-hook-modal - npm
January 4, 2026 - A React Hook library for declaratively managing modals, eliminating the need for state declarations. Props can be passed directly through function calls, simplifying modal control in your application..
      » npm install react-use-hook-modal
    
Published   Jan 04, 2026
Version   2.0.2
Author   iskkiri
🌐
Reactgo
reactgo.com › home › react modal tutorial using hooks
React Modal tutorial using hooks | Reactgo
August 19, 2023 - In this tutorial, we are going to learn about how to create a modal in react using hooks. First, we are going a set up a new react app by using the below command. ... Now change your current working directory by using the following commands. cd react-modal npm start # to start the development server · Now open the react-modal folder in your favorite code editor and navigate to App.js file and replace with below code. ... import React, { useState } from "react";import "./styles.css"; function App() { const [show, setShow] = useState(false); const openModal = () => setShow(true); const closeModal = () => setShow(false); return ( <div className="App"> <h1>Creating react modal</h1> {!show && <button onClick={openModal}>Show modal</button>} </div> ); } export default App;
🌐
Wecodetheweb
wecodetheweb.com › 2019 › 03 › 02 › easy-modals-with-react-hooks
Easy React Modals with Hooks and Portals - We code the web
March 2, 2019 - Well with the new React Hooks it can. There are several hooks you can use, but in this case we are only going to use the useState hook. We need it to keep track of if our modal is open or closed. By calling useState(initialValue) on the top of our component, we tell React to create a state value, in this case we set it to be false initially.
🌐
npm
npmjs.com › package › use-modal-hook
use-modal-hook - npm
November 6, 2022 - import React, { memo } from "react"; import { useModal, ModalProvider } from "use-modal-hook"; import Modal from "react-modal"; // It can be any modal const MyModal = memo( ({ isOpen, onClose, title, description, closeBtnLabel }) => ( <Modal isOpen={isOpen} onRequestClose={onClose}> <h2>{title}</h2> <div>{description}</div> <button onClick={onClose}>{closeBtnLabel}</button> </Modal> ) ); const SomePage = memo(() => { const [showModal, hideModal] = useModal(MyModal, { title: "My Test Modal", description: "I Like React Hooks", closeBtnLabel: "Close" }); return ( <> <h1>Test Page</h1> <button onClick={showModal}>Show Modal</button> </> ); }); const App = () => ( <ModalProvider> <SomePage /> </ModalProvider> );
      » npm install use-modal-hook
    
Published   Nov 06, 2022
Version   2.1.2
Author   alexander.khivrych
🌐
Better Programming
betterprogramming.pub › create-a-custom-usemodal-react-hook-449b5909cc09
Create a Custom useModal() React Hook | by Oyetoke Tobiloba Emmanuel | Better Programming
August 15, 2019 - Declare a setModalState function that takes in state as a prop, call setModalOpen to control the modal and set selected to null if state is false. Then we return the things that can be accessed out of the Hooks. For this example, we are going to create three components: UserTable: Displays a list of users in a table. UserDetail: Shows full details of a user. UserInformation: A component wrapper for both UserTable and UserDetail. ... What we have above is a simple React component which maps through given data and presents it in a table.
🌐
Medium
medium.com › codex › 3-simple-custom-react-hooks-for-mastering-modal-management-cc9a6fc24937
3 Simple Custom React Hooks for Mastering Modal Management | by Andrew Richard | CodeX | Medium
May 18, 2024 - Modal management, often a source of clutter and complexity, can be simplified into a streamlined and declarative process with hooks. In this article, we will dive into three custom React hooks — `useModalManager`, `useClickOutside`, and `useModal` — that epitomize the hook philosophy.
Top answer
1 of 2
2

You need to add a function in the app.js to handle the click on the button, so the function will change the state show to true, and you will pass the state to your modal, like this:

App.js

[showState, setShowState] = useState(false)
buttonClickedHandler = () => {
   setShowState((showState) => showState = !showState )
}

<div className="App">
      <HeroSlider buttonClicked={buttonClickedHandler} />
      <HowItWorks />
      <Modal show={showState} buttonClicked={buttonClickedHandler} />
      <Footer />
</div>

HeroSlider.js

import React, { useState } from "react";
import Header from './Header'

function HeroSlider(props) {
    const [show, setShow] = useState(false);
    const modalShow = () => setShow(true);
    const openIsAccount = () => {

    }
    return (

 <div className="jumbotron" id="jumbotron2" >
<button type="button" className="btn btn-primary" id="shoutBtn" onClick={props.buttonClicked}><span>Get Started</span>
</button>
 </div>
    );
}

export default HeroSlider;

IsAccountOpen.js

const IsAccountOpen = (props) => {
    const [show, setShow] = useState(false);
    const handleClose = () => setShow(false);
    const handleShow = () => setShow(true);

    return (
        <>
            <Modal show={props.show} onHide={props.buttonClicked} backdrop="static" keyboard={false}>
                <Modal.Header closeButton>
                    <Modal.Title>Modal title</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    I will not close 
                 </Modal.Body>
            </Modal>
        </>
    );

};

export default IsAccountOpen

I think the best solution is to use redux, because you will need to access and update the state from different components, you shouldn't use context API because the state changes frequently and you will hit the performance.

2 of 2
0

You'll need to extract the state to App level, so that this can be shared to components. You can do this with useState, or using context & custom hooks if you want to make it very clean. But do it with useState on first.

HeroSlider should receive modalShow function in it's props. Modal.js should receive the show state as props.