You shouldn't really manipulate the dom this way in react. The way to do this is to have your close buttons have an onClick handler that calls a callback given as a prop from the parent, i.e.
onClick
const ParentComponent = () => { const [closed, setClosed] = useState(false) const close = useCallback(() => setClosed(true), []) return <div style={closed ? { display: 'none' } : null}> <ChildComponent close={close}/> </div> } const ChildComponent = ({close}) => (<span onClick={close}>Close</span>)
Thanks you mr.Alex, 🙏 I will change it according to your suggestion, Thanks a lot
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You shouldn't really manipulate the dom this way in react. The way to do this is to have your close buttons have an
onClickhandler that calls a callback given as a prop from the parent, i.e.Thanks you mr.Alex, 🙏
I will change it according to your suggestion,
Thanks a lot