Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import './App.css'
  3. import CheckBox from './CheckBox'
  4.  
  5. class DarkFurit extends Component {
  6. constructor(props) {
  7. super(props)
  8. this.state = {
  9. fruites: [
  10. {id: 1, value: "banana", isChecked: false},
  11. {id: 2, value: "apple", isChecked: false},
  12. {id: 3, value: "mango", isChecked: false},
  13. {id: 4, value: "grap", isChecked: false}
  14. ]
  15. }
  16. }
  17.  
  18.  
  19. handleCheckChieldElement = (event) => {
  20. let fruites = this.state.fruites
  21. fruites.forEach(fruite => {
  22. if (fruite.value === event.target.value)
  23. fruite.isChecked = event.target.checked
  24. })
  25. this.setState({fruites: fruites})
  26. }
  27.  
  28. render() {
  29. return (
  30. <div className="DarkFruit">
  31. <h1> Check and Uncheck All Example </h1>
  32. <ul>
  33. {
  34. this.state.fruites.map((fruite) => {
  35. return (<CheckBox handleCheckChieldElement={this.handleCheckChieldElement} {...fruite} />)
  36. })
  37. }
  38. </ul>
  39. </div>
  40. );
  41. }
  42. }
  43.  
  44. export default DarkFurit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement