Guest User

Untitled

a guest
Jan 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3.  
  4. import "./styles.css";
  5.  
  6. class App extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. caclulatedUsage: {
  11. bath: 0,
  12. kitchen: {
  13. stove: 0,
  14. fridge: 0,
  15. dishwasher: 0
  16. },
  17. livingroom: {
  18. tv: 0,
  19. tvBox: 0
  20. }
  21. }
  22. };
  23. }
  24.  
  25. componentDidMount() {
  26. this.setState(
  27. {
  28. caclulatedUsage: Object.assign({}, this.state.access, {
  29. caclulatedUsage: {
  30. ...this.state.caclulatedUsage,
  31. bath: 12
  32. },
  33. kitchen: {
  34. ...this.state.caclulatedUsage.kitchen,
  35. stove: 14,
  36. fridge: 23,
  37. dishwasher: 34
  38. }
  39. })
  40. },
  41. () => {
  42. console.log(this.state);
  43. }
  44. );
  45. }
  46.  
  47. render() {
  48. return (
  49. <div className="App">
  50. <h1>Hello CodeSandbox</h1>
  51. {this.state.caclulatedUsage.bath}
  52. <br />
  53. {this.state.caclulatedUsage.kitchen.stove}
  54. <br />
  55. {this.state.caclulatedUsage.kitchen.fridge}
  56. <br />
  57. {this.state.caclulatedUsage.kitchen.dishwasher}
  58. </div>
  59. );
  60. }
  61. }
  62.  
  63. const rootElement = document.getElementById("root");
  64. ReactDOM.render(<App />, rootElement);
Add Comment
Please, Sign In to add comment