App.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import User from './User';
  3. import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
  4. import Navigation from './Navigation';
  5. import Footer from './Footer';
  6. import Home from './Home';
  7. import About from './About';
  8. export class App extends React.Component{
  9. constructor(props){
  10. super(props)
  11. this.state = {
  12. userList: [
  13. {name: "Hugo", counter: 0},
  14. {name: "Bert", counter: 0},
  15. {name: "Sepp", counter: 0},
  16. {name: "Lisa", counter: 0},
  17. {name: "Susi", counter: 0},
  18. ]
  19. }
  20. }
  21. doClick(idx){
  22. let listCopy = this.state.userList.slice();
  23. listCopy[idx].counter++;
  24. this.setState({userList: listCopy})
  25. }
  26. hello(){
  27. return <p>hello</p>
  28. }
  29. render(){
  30. return (
  31. <div>
  32. <Router>
  33. <Navigation />
  34. <Switch>
  35. <Route path="/" exact component={Home} />
  36. <Route path="/about" exact component={About} />
  37. </Switch>
  38. <Footer />
  39. </Router>
  40. {this.props.title}
  41. {this.state.userList.map((user, idx) =>
  42. <User
  43. name={user.name}
  44. counter={user.counter}
  45. doClick={() => this.doClick(idx)}
  46. app={this}
  47. title={this.props.title}
  48. />
  49. )}
  50. </div>
  51. )
  52. }
  53. }