DEV Community

Discussion on: Building a modal in React.

Collapse
 
ditoorkodashvili profile image
Dito

Hi,
why use two functions (openModalHandler and closeModalHandler) when you can simply have:

toggleModal = () => {
this.setState(prevState=> {
isShowing: !prevState.isShowing
})
}

and also in this kind of situations wouldn't it be more optimal to use functional component with react hooks instead of class?

Collapse
 
achowba profile image
Prince

Thanks for the suggestion on using the conditional operator. Also, at the time this post was published, React Hooks didn't exist.