0

I have a React class component that allows some details to be hidden or shown when a button is clicked in the app.

I intialised the state to be as below;

class Admin extends React.Component {
constructor(props){
  super(props)
  this.state = {
    show: false,
  }
}

and then updated the state property like below;

const handleDetails = (props) => {
  this.setState(prevState => ({
    show: !prevState.show}))
}

The project runs, but when the handleDetails function is called, it returns an error of

Cannot read property 'setState' of undefined
Dansiecrown
  • 33
  • 1
  • 6
  • 1
    Where is `handleDetails` declared and where is it being called? Can you provide a more comprehensive code example? https://stackoverflow.com/help/minimal-reproducible-example – Drew Reese Aug 12 '21 at 00:53

0 Answers0