CodeMasteryLab
Section 1

Getting Started with React

Learn the basics of React and set up your development environment

Getting Started with React

What is React?

React is a JavaScript library for building user interfaces. It lets you compose complex UIs from small, isolated pieces of code called "components."

Why React?

  • Declarative: React makes it painless to create interactive UIs
  • Component-Based: Build encapsulated components that manage their own state
  • Learn Once, Write Anywhere: Develop new features without rewriting existing code

Setting Up Your Environment

To get started with React, you need Node.js installed on your computer.

# Create a new React app
npx create-react-app my-app
cd my-app
npm start

Your First Component

Here's a simple React component:

function Welcome() {
  return <h1>Hello, React!</h1>;
}

export default Welcome;

JSX Syntax

JSX is a syntax extension to JavaScript. It looks like HTML but has the full power of JavaScript.

const element = <h1>Hello, world!</h1>;

Key Concepts

  1. Components - Building blocks of React apps
  2. Props - Pass data to components
  3. State - Manage component data
  4. Events - Handle user interactions

Practice Exercise

Create a simple greeting component that displays your name.