2
respostas

TypeError: can't access property "inscrever", this.props.categories is undefined

Eu estou em dúvida que está me dando esse type error. Segue o código abaixo:

 constructor(props) {
    super(props);
    this.title = "";
    this.text = "";
    this.category = "Sem categoria";
    this.state = {categories: []}
  }

  componentDidMount(){
    this.props.categories.inscrever(this._newCategories.bind(this));
  }

  _newCategories(categories){
    this.setState({...this.state, categories});
  }

  _mudarCategoria(evento){
    evento.stopPropagation();
    this.category = evento.target.value;
  }


  _handleMudarTitulo(evento) {
    evento.stopPropagation();
    this.title = evento.target.value;
  }
 constructor(){
    super();
    this.state = {notes: []}
  }

componentDidMount(){
  this.props.notes.inscrever(this._newNotes.bind(this));
}

_newNotes(notes){
  this.setState({...this.state, notes})
}

  render() {
    return (
      <ul className="lista-notas">
        {this.state.notes.map((nota, index) => {
          return (
            <li className="lista-notas_item" key={index}>
              <NoteCard
                indice ={index}
                apagarNota={this.props.apagarNota}
                title={nota.title}
                text={nota.text}
                category = {nota.category}
              />
            </li>
          );
        })}
      </ul>
    );
  }
}

export default NoteList;
2 respostas

TypeError: can't access property "inscrever", this.props.notes is undefined componentDidMount src/componentes/NoteList/NoteList.jsx:21

18 | } 19 | 20 | componentDidMount(){

21 | this.props.notes.inscrever(this._newNotes.bind(this)); 22 | } 23 | 24 | _newNotes(notes){

Eu estou com esse problema também com relação às notas!

Fala Vinicius, tudo bem?

Você passou notes como propriedade para o componente ListaDeNotas? Se sim, poderia nos enviar o código completo de app.js ou se possível nos enviar o projeto por completo?

Aguardo o seu retorno :D

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software