Managing the Internal State
Components have the ability to store data that can change over time.
When a component shows data that can change over time, we want changes to be shown as soon as possible. For example, consider the ProductList
component: it shows a list of products contained in the products
array. If a new product is added to the array, we want it to be shown immediately. React provides a mechanism to support the automatic rendering of a component when data changes. Such a mechanism is based on the concept of state.
Note
React state
is a property that represents data that changes over time. Every component supports the state
property, but it should be used carefully.
Again, consider the ProductList
component:
import React from 'react'; import Product from './Product'; class ProductList extends React.Component { render() { let products = [ {code:"P01", name: "Traditional Merlot", description: "A bottle of middle weight wine, lower in tannins (smoother), with a more...