Your first component
tsx
type WelcomeProps = { name: string };
export function Welcome({ name }: WelcomeProps) {
return <h1>Hello, {name}</h1>;
}JSX rules
- Return one parent element
- Use
classNameinstead ofclass - Use camelCase for DOM props (
onClick,tabIndex) - Embed JavaScript with
{}
tsx
const title = 'React Basics';
return <h2>{title}</h2>;Rendering components
tsx
function App() {
return (
<main>
<Welcome name="Alex" />
</main>
);
}Fragments
Use fragments to avoid unnecessary wrapper nodes:
tsx
return (
<>
<h1>Title</h1>
<p>Description</p>
</>
);Comments in JSX
tsx
return <div>{/* This is a JSX comment */}</div>;Next, we will dive deeper into JSX and rendering behavior.