Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

69
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!