Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

382
Views
In react, how do I close a popup confirmation?

The popup confirmation should be closed when any part of the screen outside the popup is clicked. But the popup remains on the page even after the outside is being clicked. And it keeps displaying " Line 2:8: 'Backdrop' is defined but never used no-unused-vars Line 3:8: 'Modal' is defined but never used no-unused-vars" in my terminal. Here is my code.

#Todo.js

import {useState} from 'react'

import Modal from './Modal'

import Backdrop from './Backdrop'

function Todo(props){
const [modalIsOpen, setModalIsOPen] = useState(false)

  function deleteHandler(){
    setModalIsOPen(true)
  }

  function closeModalHandler(){
    setModalIsOPen(false)
  } 

   return <div className='card'>
   <h2> { props.text} </h2>
   <div className='actions'>
   <button onClick={deleteHandler}>Delete</button>

   </div>
   {modalIsOpen && <Modal/>}
   {modalIsOpen && <Backdrop onCancel={closeModalHandler} />}


 </div>
}

export default Todo;

#Backdrop.js

import propTypes from "prop-types"

function Backdrop(props){

    return <div className='backdrop' onClick={propTypes.onCancel}/>
}

export default Backdrop

#Modal.js

function Modal(){
    return <div className='modal'>
        <p>Are you sure?</p>
        <button className='btn-alt'>Cancel</button>
        <button className='btn'>Confirm</button>
    </div>
}

export default Modal
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firstly, I think your Modal has props problem

return <div className='backdrop' onClick={propTypes.onCancel}/>

It should be like this onClick={props.onCancel} because you're using props instead of propTypes.

Secondly, for the warning you get

Line 2:8: 'Backdrop' is defined but never used no-unused-vars Line 3:8: 'Modal' is defined but never used no-unused-vars

If you're using eslint, you need to check your .eslintrc should have some configs like below

"extends": [
    "eslint:recommended",
    "plugin:react/recommended"
]

If it's not there you can install it

npm install eslint@7 --save-dev
npm install eslint-plugin-react --save-dev
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!