Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,560 questions

51,419 answers

573 users

How to add state with array to class App and output the array in React JS

1 Answer

0 votes
// todo/src/projects/ToDo.js

import React, { Component } from 'react';

class ToDo extends Component {
    render() {
        return this.props.todo.map((td) => (
             <h2>{`${td.id} - ${td.mission} - ${td.completed}`}</h2>
        ));
    }
}


export default ToDo;
// App.js

import React, { Component } from 'react';
import './App.css';
import ToDo from './projects/ToDo'

class App extends Component {
    state = {
      todoApp: [
        {
          id: 1234,
          mission: 'Read a book',
          completed: false
        },
        {
          id: 9872,
          mission: 'Watch a movie',
          completed: false
        },
        {
          id: 7389,
          mission: 'Write the code',
          completed: true
        },
        {
          id: 5621,
          mission: 'Play with kids',
          completed: true
        },
      ]
    }
    render() {
        return (
          <div className="App">
            { /* Component*/ }
            <ToDo todo={this.state.todoApp}/>
          </div>
      );
    }
}

export default App;



/*
run:

1234 - Read a book - false
9872 - Watch a movie - false
7389 - Write the code - true
5621 - Play with kids - true

*/

 



answered Mar 24, 2020 by avibootz
edited Mar 25, 2020 by avibootz

Related questions

...