Giter Site home page Giter Site logo

flw2-u2l2-23-24-student-exercises-part-1's Introduction

Lesson 2.2 - Components, JSX, and Props

๐Ÿ” Key Concepts

React Components

  • Definition: Functions that return UI elements to be rendered
  • Key Characteristics:
    • Independent and reusable
    • Can return HTML through JSX
    • Start with capital letters
    • Can be used multiple times, each use being an instance

JSX (JavaScript XML)

  • Definition: Syntax extension for JavaScript, allowing UI structuring with a syntax similar to XML/HTML.
  • Key Characteristics:
    • Use className instead of class
    • Components are self-closing (like <Component />)
    • Place JavaScript within curly braces {}
    • Only one root HTML element per component

Props (Properties)

  • Definition: Arguments passed into React components
  • Key Characteristics:
    • Allow dynamic data pass between components
    • Make components reusable
    • Defined as attributes in component tags (e.g., <Component prop="value" />)
    • Accessed within components as props.propName

๐Ÿš€ Quick Code Reference

Basic React Component with Props

import React from "react";

function GreetByName(props) {
  return <div>Hello {props.name}!</div>;
}

function App() {
  return (
    <div className="App">
      <GreetByName name="Jared" />
    </div>
  );
}

export default App;

Passing and Accessing Multiple Props

function Greet(props) {
  return <div>Hello {props.firstName} {props.lastName}!</div>;
}

function App() {
  return (
    <div>
      <Greet firstName="Jane" lastName="Doe" />
    </div>
  );
}

๐Ÿ“š Additional Resources

flw2-u2l2-23-24-student-exercises-part-1's People

Contributors

cn-mika avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.