This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Route, Switch } from "react-router-dom"; | |
import Nav from "components/Nav/Nav"; | |
import Cart from "components/Cart/Cart"; | |
import Main from "components/Main/Main"; | |
const App = props => [ | |
<Nav key={1} />, | |
<Routes key={2} /> | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import { Route, Switch } from "react-router-dom"; | |
import Nav from "components/Nav/Nav"; | |
import Cart from "components/Cart/Cart"; | |
import Main from "components/Main/Main"; | |
import data from "MOCK_DATA.json"; | |
class App extends Component { | |
constructor() { | |
super(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import { Route, Switch } from "react-router-dom"; | |
import Nav from "components/Nav/Nav"; | |
import Cart from "components/Cart/Cart"; | |
import Main from "components/Main/Main"; | |
import Item from "components/Item/Item"; | |
import data from "MOCK_DATA.json"; | |
class App extends Component { | |
constructor() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import { Route, Switch } from "react-router-dom"; | |
import Nav from "components/Nav/Nav"; | |
import Cart from "components/Cart/Cart"; | |
import Main from "components/Main/Main"; | |
import Item from "components/Item/Item"; | |
import data from "MOCK_DATA.json"; | |
class App extends Component { | |
constructor() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Link } from 'react-router-dom'; | |
const Main = props => { | |
if(props.products) { | |
return <RenderProducts products={props.products}/> | |
} else { | |
return <RenderLoading /> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import { Route, Switch } from "react-router-dom"; | |
import Nav from "components/Nav/Nav"; | |
import Cart from "components/Cart/Cart"; | |
import Main from "components/Main/Main"; | |
import Item from "components/Item/Item"; | |
import data from "MOCK_DATA.json"; | |
class App extends Component { | |
constructor() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wrong | |
this.setState({ | |
counter: this.state.counter + this.props.increment, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Correct | |
this.setState((prevState, props) => ({ | |
counter: prevState.counter + props.increment | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidUpdate(prevProps, prevState) { | |
// only update chart if the data has changed | |
if (prevProps.data !== this.props.data) { | |
this.chart = c3.load({ | |
data: this.props.data | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
class Item extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
selectedProduct: {} | |
}; | |
}; |