React Fundamentals
Start your React journey! Learn about JSX, Components, Props, and the Virtual DOM.
Start your React journey! Learn about JSX, Components, Props, and the Virtual DOM. This hands-on tutorial focuses on practical implementation of react fundamentals concepts.
React Fundamentals
React is all about Components. A component is a small, reusable piece of code that represents a part of the UI.
1. JSX (JavaScript XML) π
React uses a syntax called JSX. It looks like HTML, but it's actually JavaScript.
Why use JSX? It allows us to keep the logic (JS) and the view (HTML) in the same file.
Rules of JSX:
- Return One Parent: You must wrap everything in a single tag (like
<div>or<>...</>). - CamelCase: Use
classNameinstead ofclass,onClickinstead ofonclick. - Close Tags: Self-closing tags must end with
/>(e.g.,<img />).
2. Creating Components π§±
A React component is just a JavaScript function that returns JSX.
Note: Component names MUST start with a Capital Letter.
3. Props (Properties) π
Props are how we pass data down from a parent to a child. They are like HTML attributes.
Important: Props are Read-Only. A child cannot change its props.
4. Conditional Rendering π
We use standard JavaScript logic (if/else, ternary operators) to decide what to show.
5. Lists & Keys π
To render a list of items, we use the .map() array method.
Why key?
React needs a unique key for each item to track changes efficiently.
AI Mentor
Confused about "React fundamentals, JSX syntax, functional components, props, and conditional rendering"? Ask our AI mentor for a simplified explanation.
Quiz
Quiz
Question 1 of 4What is JSX?
Key Takeaways
β
JSX mixes HTML and JS.
β
Components are functions starting with a Capital Letter.
β
Props pass data down.
β
Keys are required for lists.
What's Next?
Static components are boring. Let's make them interactive with React Hooks!
Keep coding! π