⊗jsrtPmCoDt 92 of 112 menu

Component Data in React

Component data can be stored in three places: in props, in component variables and constants, and in states. Props store data that is sent to a component from the outside by its parent component. At the same time, props must remain unchanged inside the component.

Variables, constants, and states should be used to store local data that is important to the component itself and that the parent should not know about. States should be used to store data that can change in different events and you want the changes to be reactive.

Given a certain component:

function Test() { // definition of isEdit, elem and data if (isEdit) { elem = <input value={data} />; } else { elem = <span>{data}</span>; } return <div> {elem} </div>; }

Determine whether isEdit, elem, and data can be props, state, variables, or constants.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline