Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from "react";
- import ReactDOM from "react-dom";
- import "./styles.css";
- class App extends Component {
- constructor(props) {
- super(props);
- this.state = {
- caclulatedUsage: {
- bath: 0,
- kitchen: {
- stove: 0,
- fridge: 0,
- dishwasher: 0
- },
- livingroom: {
- tv: 0,
- tvBox: 0
- }
- }
- };
- }
- componentDidMount() {
- this.setState(
- {
- caclulatedUsage: Object.assign({}, this.state.access, {
- caclulatedUsage: {
- ...this.state.caclulatedUsage,
- bath: 12
- },
- kitchen: {
- ...this.state.caclulatedUsage.kitchen,
- stove: 14,
- fridge: 23,
- dishwasher: 34
- }
- })
- },
- () => {
- console.log(this.state);
- }
- );
- }
- render() {
- return (
- <div className="App">
- <h1>Hello CodeSandbox</h1>
- {this.state.caclulatedUsage.bath}
- <br />
- {this.state.caclulatedUsage.kitchen.stove}
- <br />
- {this.state.caclulatedUsage.kitchen.fridge}
- <br />
- {this.state.caclulatedUsage.kitchen.dishwasher}
- </div>
- );
- }
- }
- const rootElement = document.getElementById("root");
- ReactDOM.render(<App />, rootElement);
Add Comment
Please, Sign In to add comment