March 2019
Beginner to intermediate
324 pages
7h 17m
English
The state object should be initialized at the constructor of the React component class that needs this state. For our product page, the data we need to store is simply the product information. Here is us initializing the state object:
class CardContainer extends React.Component { constructor(props) { //pass props to the parent component super(props); //initialize the state object for this component this.state = { cards: [] }; } /* Rest of the card container code */}
A constructor for a component object expects props as an argument, so the first thing we need to do is pass props to the parent React.Component object.
The second step is to initialize the state object of our component. state objects are internal ...
Read now
Unlock full access