Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. class App extends Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. people: [
  6. {
  7. 'firstname': "Paul",
  8. 'id': "1"
  9. },
  10. {
  11. 'firstname': "Martin",
  12. 'id': "2"
  13. },
  14. {
  15. 'firstname': "Joseph",
  16. 'id': "3"
  17. },
  18. {
  19. 'firstname': "Gregor",
  20. 'id': "4"
  21. }
  22. ],
  23. peopleChecked: [
  24. {
  25. 'firstname': "Martin",
  26. 'id': "2"
  27. },
  28. {
  29. 'firstname': "Gregor",
  30. 'id': "4"
  31. }
  32. ],
  33. selectPeopleId: []
  34. }
  35. }
  36.  
  37. handleSelect = (person) => {
  38. this.setState({
  39. selectPeopleId: person.id
  40. })
  41. }
  42.  
  43.  
  44. render() {
  45. return (
  46. <div>
  47. {this.state.people.map(person => (
  48. <div key={person.id} className="mb-1">
  49. <Form.Check
  50. type={'checkbox'}
  51. id={person.id}
  52. label={person.firstname}
  53. checked={this.state.peopleChecked.some(({ id}) => id === person.id)}
  54. onChange = {() => this.handleSelect(person)}
  55. />
  56. </div>
  57. ))}
  58. </div>
  59. );
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement