Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

react - this.state returning undefined inside a prop argument

I am at component props and I want to get a state element of the class. But when I call this.state it is returning undefined. Here is the code:

        <div>
          {this.addRestricao().map((el, i) => (
            <Restricao
              key={i}
              getArray={array => {
                debugger;
                // if (i === 0) {
                //   this.setState({ matrizRestricoes: [] });
                // }
                let matrizRestr = this.state.matrizRestricoes;
                
                matrizRestr[matrizRestr.length] = array;

                this.setState({ matrizRestricoes: matrizRestr });
              }}
            />
          ))}

        </div>
       

How can I access the state value?

Comments