24
loading...
This website collects cookies to deliver better user experience
type
The type property is a string reference to the HTML tag. React internally calls it a Component Element.
When we do import main from "../components/main" the name of the component becomes the type that is imported.
key
Used to uniquely identify elements among siblings.
This is created when we are manually creating a bunch of children's i.e when we map through the array and render a bunch of components with different data. We use a key while rendering those and hence the key is substituted to this property.
Example
this.state.data.map((item,i) => <li key={i}>Test</li>)
ref
ref is reference to a actual DOM node. If you ever have used the create ref function or the useRef hook that's where this values end up.
$$typeof
This is actually a safety feature. Its values are always a symbol. What is a symbol?
So if you have a compromised server that you are making an API call and you get back some data and you try to render it through your components. React will straight up reject that.
Props
In our case, we just had 1 child that is an h1 hence type is an h1. key and ref are null
And its children was a text string with "look ma!" and with id title.
Children can be an object or array of an objects.
As we clicked the element product list goes away hence it's also removed from the DOM.
There is a difference between the native DOM element and the component element.
Over here we see the sequence the older items are there is just we have added a new DOM node and changed the sequence but react doesn't understand this. It goes and sees the first node is changed and remove the previous DOM node that is star wars and replace it with Spaceballs similarly for the second and sees the third has been added hence adding the third one.
Here we see we are rendering all of the elements again and again but we can save these things with keys.