![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
react-hook-modal
Advanced tools
A custom modal, with a custom hook for modal handling in React App
A custom modal, with a custom hook for handling modals in React applications. This package allows us to centralize the logic for rendering modal components. Through a hook, we can dynamically render any coponent in this modal. This gives us flexibility in our components since we would not have to handle local states for modal rendering. For that we use the hook useModal
npm install --save react-hook-modal
The "react-hook-modal" api consists of a hook: useModal, a component containing the modals: Modal, and a HOC ModalDataContextProvider. react-hook-modal, uses the react Context api to exchange states and information to be rendered in the modal through all the components of our application.
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App/App';
////////////////////////////////////
import { ModalDataContextProvider } from 'react-hook-modal';
////////////////////////////////////
ReactDOM.render(
////////////////////////////////////
<ModalDataContextProvider>
<App />
</ModalDataContextProvider>,
////////////////////////////////////
document.getElementById('root')
);
...
import { Modal, useModal } from 'react-hook-modal';
import 'react-hook-modal/dist/index.css';
...
return (
<div className='App'>
<Header />
{/* Modal section here */}
<Modal />
</div>
);
...
import { Modal, useModal } from 'react-hook-modal';
...
const { setComponentToRender, closeModal } = useModal(onCloseModal);
function onCloseModal(data){
console.log("Modal closed",data);
}
return (
<button
style={{ color: '#fff' }}
type="button"
onClick={() => {
setComponentToRender(<AccountCustomComponent />, {
title: 'My Account',
animation: true,
closeOnBackgroundOrEsc: false,
});
}}
>
Open Modal
</button>
)
The Modal component has props to customize the styles of the container, header and body sections. here an example of setting different styles:
<Modal
styles={{
container: {
backgroundColor: '#1C1C1C',
color: '#fff',
width: '55rem',
maxHeight: '100vh',
maxWidth: '100vw'
},
header: { backgroundColor: '#2C2C2C', color: '#fff' },
body: { maxHeight: '80vh', padding: '0rem' }
}}
/>
The Modal component has a prop called classContainer which defines a custom container Modal class but it is recommended include the following css styles.
.app-modal {
position: fixed;
max-height: 100vh;
max-width: 100vw;
z-index: 999;
top: 50%;
left: 50%;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.2);
transform: translate(-50%, -50%);
background-color: white;
color: inherit;
width: 50rem;
}
The setComponentToRender(element: JSX.Element, options?: ModalOptions) function takes a JSX.Element which can be a component or just an 'html' and renders it inside the body of the Modal.
options allow you to dynamically set the attributes and properties of the modal to be represented.
export interface ModalOptions {
title?: string; // A title to display in the header
dataProps?: any; // An object passed to the Modal state to share data: we can access **const {dataToProps} = useModal()
width?: string | number; // Set the width for the modal
height?: string | number; // Set the height for the modal
closeOnBackgroundOrEsc?: boolean | undefined; // Closes the modal if we click outside the modal context or if we press the Esc key.
resizable?: boolean; // Make a resizable Modal
fullScreen?: boolean; // Complete viewport size
animation?: boolean; // Make a nice animation on open the modal
footer?: JSX.Element | null | undefined; // A component for the footer
darkMode?: boolean; // Enable dark mode
}
MIT © josealejandro2928
FAQs
A custom modal, with a custom hook for modal handling in React App
We found that react-hook-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.