Reactjs `openAlertAbsent` is not a function

After opening the popup, when i click the icon close i’ve receive an error saying openAlertAbsent is not a function`

const [openAlertAbsent, setOpenAlertAbsent] = useState({
        open: false,
        success: false,
      });

 .....
setOpenAlertAbsent({
  open: true,
  success: true,
})
 .....

  const handleAbsent = () =>{
    if (openAlertAbsent.success) {
      openAlertAbsent({
        open: false,
        success: false,
      });
    }
  }


  ....

   <AlertIgnoreStudent
        open={openAlertAbsent.open}
        handleClose={handleAbsent}
        success={openAlertAbsent.success}
   />

>Solution :

const [openAlertAbsent, setOpenAlertAbsent] = useState({
        open: false,
        success: false,
      });

 .....
setOpenAlertAbsent({
  open: true,
  success: true,
})
 .....

  const handleAbsent = () =>{
    if (openAlertAbsent.success) {
      openAlertAbsent({  // here is a problem, maybe setOpenAlertAbsent?
        open: false,
        success: false,
      });
    }
  }


  ....

   <AlertIgnoreStudent
        open={openAlertAbsent.open}
        handleClose={handleAbsent}
        success={openAlertAbsent.success}
   />

Leave a Reply