Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

80
Visualizações
Adding custom tag stops rendering of the page

class TodoList extends Component {

     List = props => (
  <ul>
    {
      props.items.map((item, index) => <li key={index}>{item}</li>)
    }
  </ul>
);

    state = {
      term: '',
      items: []
    };
    onChange = (event) => {
    this.setState({term: event.target.value});
  }
onSubmit = (event) => {
    event.preventDefault()
    this.setState({
      term: '',
      items: [...this.state.items, this.state.term]
    });
  }
    handleClick=()=>{
   this.setState(({count})=>({
       count: count+1
   }));
    };
    render() {
        return (
            <>
                <div>
                    <h2>
                        Todo List
                    </h2>
                    <form className="App" onSubmit={this.onSubmit}>
       <input value={this.state.term} onChange={this.onChange} />
       <button>Submit</button>
   </form>
<List items={this.state.items}/>

                </div>
                <style>{`
                    .is-done {
                        text-decoration: line-through;
                    }
                `}</style>
            </>
        );
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.0.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.0.0/umd/react-dom.production.min.js"></script>

The above code renders fine if I remove the tag below the form tag <List items={this.state.items}/> Not sure what could be the reason for this. I am making a simple
todo list here. It shows the submit button along with input text box and the heading Todo List . But with that last tag <List added it doesn't show anything and there is a blank page

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The advice to move it outside the class is fine, and you SHOULD do it, but you should also understand why it didn't work.

The smallest fix you could do, and it WOULD work that way would be to change

<List items={this.state.items}/>

to

<this.List items={this.state.items}/>

Why? Because the functional component is created inside the class, and thus when React translates JSX code into JS functions - inside the class it is a method belonging to the class (and we know these should be called with this).

If you take it outside the class, then you don't need this, because it is in the same scope as the class definition.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda