-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
10-modal-development #49
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, good job!
Step by step it is looking more and more interesting :)
So the main idea is to make this component dependent on the props, to control it outside itself, try to think about it.
return ( | ||
<div className={styles.modalBackground}> | ||
<div className={styles.modalContainer}> | ||
const ModalWidget = ({header, paragraph, cancelText, confirmText, onConfirm,}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is unnecessary comma after last prop
const [openModal, setOpenModal] = useState(true); | ||
const switchModal = () => { | ||
setOpenModal(!openModal); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openModal should be passed as a prop "open" and then we will be able to control the state outside the component
<button className={`${styles.modalButton} ${styles.confirm}`}>Confirm</button> | ||
</div> | ||
</div> | ||
document.body.addEventListener('keydown', pressEscape); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, move it to useEffect function, but not the returned one, above return.
|
||
return ( | ||
<div> | ||
<button onClick={switchModal}> Show modal </button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we will have open prop state, then we don't have to have a button here :)
<button className={`${styles.modalButton} ${styles.cancel}`} onClick={switchModal}> | ||
{cancelText} | ||
</button> | ||
<button className={`${styles.modalButton} ${styles.confirm}`} onClick={pressConfirm}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onClick can just include function which will be passed and we don't have to wrap it with another one
No description provided.