-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5618 from PR4NJ41/dev-10-Refactored-'modal.jsx'
Refactored 'modal.jsx' from Class component to Functional Component
- Loading branch information
Showing
1 changed file
with
21 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import React from 'react'; | ||
import createReactClass from 'create-react-class'; | ||
import React, { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Modal = createReactClass({ | ||
propTypes: { | ||
modalClass: PropTypes.string, | ||
children: PropTypes.node | ||
}, | ||
componentDidMount() { | ||
return document.querySelector('body')?.classList.add('modal-open'); | ||
}, | ||
componentWillUnmount() { | ||
return document.querySelector('body')?.classList.remove('modal-open'); | ||
}, | ||
render() { | ||
const className = `wizard active ${this.props.modalClass}`; | ||
return ( | ||
<div className={className}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} | ||
); | ||
const Modal = (props) => { | ||
useEffect(() => { | ||
document.querySelector('body')?.classList.add('modal-open'); | ||
return () => { | ||
document.querySelector('body')?.classList.remove('modal-open'); | ||
}; | ||
}, []); | ||
|
||
const className = `wizard active ${props.modalClass}`; | ||
return ( | ||
<div className={className}> | ||
{props.children} | ||
</div> | ||
); | ||
}; | ||
|
||
Modal.propTypes = { | ||
modalClass: PropTypes.string, | ||
children: PropTypes.node | ||
}; | ||
|
||
export default Modal; |