diff --git a/snippets/Modal.md b/snippets/Modal.md index ee1fabedb..189f153ed 100644 --- a/snippets/Modal.md +++ b/snippets/Modal.md @@ -9,10 +9,8 @@ The Modal Component has following attributes: - `isVisible`, Boolean describing if the modal should be shown or not.(Required) - `title`, String describing title of Modal.(Required) - `content`, JSX elements to be rendered in modal body.(Required) -- `footer`, JSX elements to be rendered in modal footer. (optional) -- `onClose`, Function that will be called when Modal needs to be closed like when escape key is pressed.(Required) - - +- `footer`, JSX elements to be rendered in modal footer.(optional) +- `onClose`, Function that will be called when Modal needs to be closed like when escape key is pressed.(Required) ```css .modal { @@ -84,16 +82,13 @@ The Modal Component has following attributes: } ``` - ```jsx function Modal(props){ const { isVisible, title, content, footer, onClose } = props; - - useEffect(() => { + + React.useEffect(() => { document.addEventListener('keydown', keydownHandler); - return () => { - document.removeEventListener('keydown', keydownHandler); - }; + return () => document.removeEventListener('keydown', keydownHandler); }); function keydownHandler({ key }) { @@ -105,7 +100,7 @@ function Modal(props){ return !isVisible ? null : (
-
e.stopPropagation()}> +
e.stopPropagation()}>

{title}

× @@ -123,14 +118,26 @@ function Modal(props){ ```jsx //Add the component to render function -ReactDOM.render( - The content goes here

} - footer={} - onClose ={()=> } //Add action to hide modal -/>, - document.getElementById('root') -); +function App() { + const [ isModal, setModal] = React.useState(false); + + return ( + + + Add your content here

} + footer = {} + onClose ={()=> setModal(false)} + /> +
+ ) +} + +ReactDOM.render( , document.getElementById('root')); ``` + + + + \ No newline at end of file