React Components and JSX Explained

A React component is a function which returns JSX. When you use that component inside another component, the React creates an element. <Ali /> refers to element of Ali component. So, when React sees <Ali /> it gets it's JSX and internally call React.createElement with details of Ali component such as props, key and children. React.createElement creates an object which is basically description of what needs to be rendered. Then React adds that to the virtual DOM and gets added to real DOM. Tried my best to simplify this concept. Thinking of writing a blog on it. You can subscribe to my newsletter to read in-depth. link in comment. #react #javascript #frontend #programming

I recently started writing on X, mind connecting? https://x.com/thataliraza

Good read, learned this a while back from a Frontarm course. Solid summary, btw. Sharing the link for anyone curious to go a bit deeper:https://frontarm.com/courses/react-fundamentals/

Note: The virtual DOM isn't fast because diffing is fast. Diffing is actually extra work compared to direct DOM manipulation. It's fast because it batches updates. If your component updates three state values in quick succession, React doesn't touch the DOM three times. It creates three-element trees, diffs the final result against the current DOM, and makes one surgical update. That batching is what makes React feel smooth in complex UIs. Ali Raza

React docs are really great to read, they talk about this and also how re-renders work, there’s a small difference compared to the initial render you mentioned. It’s pretty interesting to think about how something we use every day actually works under the hood

You simplified it very well. This is a great breakdown of how React turns components into elements and eventually renders them. A blog on this would definitely be helpful.

I would love to read this in in-depth, thanks for sharing sir Ali Raza

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories