Props in React

Primitives โ€ข Objects โ€ข Functions โ€ข Children โ€ข Defaults
Primitive Object & Array Function children Defaults & Rest
๐Ÿ“˜ CH05-S07 ยท React Foundations
โš› FixWins.com
Chapter 05
ยฉ 2026 ยท FixWins.com
01 / 07

๐Ÿ”ด Primitive Props

LIVE

UserCard Component

PRIMITIVES String, Number, Boolean

Alice

Age: 28

โœ… Active

๐Ÿ’ก
Wrap non-string values in curly braces {'{ }'} to pass them as their actual JavaScript types.
PRIMITIVES
// --- App.jsx (Parent) ---
import React from 'react';
import UserCard from './UserCard';

const App = () => {
  return (
    <div className="app">
      {/* Passing string, number, and boolean props */}
      <UserCard name="Alice" age={28} isActive={true} />
    </div>
  );
};

// --- UserCard.jsx (Child) ---
const UserCard = ({ name, age, isActive }) => {
  return (
    <div className="card">
      <h2>{name}</h2>
      <p>Age: {age}</p>
      <p>Status: {isActive ? 'Active' : 'Inactive'}</p>
    </div>
  );
};

export default App;
ยฉ 2026 ยท FixWins.com
02 / 07

๐Ÿ”ด Object & Array Props

LIVE

UserProfile Component

COMPLEX Object & Array

Bob (Admin)

    ๐Ÿ’ก
    Pass objects and arrays directly inside {'{ }'}. Use .map() to render array items in JSX.
    OBJECT & ARRAY
    // --- App.jsx (Parent) ---
    import React from 'react';
    import UserProfile from './UserProfile';
    
    const App = () => {
      const userData = { name: 'Bob', role: 'Admin' };
      const hobbyList = ['coding', 'gaming', 'reading'];
    
      return (
        <div className="app">
          {/* Passing objects and arrays directly */}
          <UserProfile user={userData} hobbies={hobbyList} />
        </div>
      );
    };
    
    // --- UserProfile.jsx (Child) ---
    const UserProfile = ({ user, hobbies }) => {
      return (
        <div className="profile">
          <h2>{user.name} ({user.role})</h2>
          <ul>
            {hobbies.map((hobby, i) => (
              <li key={i}>{hobby}</li>
            ))}
          </ul>
        </div>
      );
    };
    
    export default App;
    ยฉ 2026 ยท FixWins.com
    03 / 07

    ๐Ÿ”ด Function Props

    LIVE

    ActionButton Component

    CALLBACK Function Prop

    Click a button...
    ๐Ÿ’ก
    Pass functions to children to allow them to update parent state. This is called Lifting State Up.
    FUNCTION
    // --- App.jsx (Parent) ---
    import React, { useState } from 'react';
    import ActionButton from './ActionButton';
    
    const App = () => {
      const [action, setAction] = useState('None');
    
      const handleSave = () => setAction('Saved!');
      const handleDelete = () => setAction('Deleted!');
    
      return (
        <div className="app">
          {/* Passing functions as props */}
          <ActionButton label="Save" onClick={handleSave} />
          <ActionButton label="Delete" onClick={handleDelete} />
          <p>Last action: {action}</p>
        </div>
      );
    };
    
    // --- ActionButton.jsx (Child) ---
    const ActionButton = ({ label, onClick }) => {
      return (
        <button onClick={onClick}>
          {label}
        </button>
      );
    };
    
    export default App;
    ยฉ 2026 ยท FixWins.com
    04 / 07

    ๐Ÿ”ด The children Prop

    LIVE

    Card Wrapper Component

    COMPOSITION children

    Welcome
    Hello, default content.
    Custom
    Nested JSX here!
    ๐Ÿ’ก
    Use children to create reusable wrapper components (like modals, cards, or layouts) without knowing their content ahead of time.
    CHILDREN
    // --- App.jsx (Parent) ---
    import React from 'react';
    import Card from './Card';
    
    const App = () => {
      return (
        <div className="app">
          {/* Passing nested JSX as children */}
          <Card title="Welcome">
            <p>Hello, this is default content!</p>
          </Card>
          
          <Card title="Custom">
            <img src="logo.png" alt="Logo" />
            <span>Any JSX works here!</span>
          </Card>
        </div>
      );
    };
    
    // --- Card.jsx (Child) ---
    const Card = ({ title, children }) => {
      return (
        <div className="card-wrapper">
          <h3>{title}</h3>
          <div className="card-body">
            {children}
          </div>
        </div>
      );
    };
    
    export default App;
    ยฉ 2026 ยท FixWins.com
    05 / 07

    ๐Ÿ”ด Defaults & Rest Props

    LIVE

    Badge Component

    FALLBACKS Defaults & Rest

    Default Alert 5
    ๐Ÿ’ก
    Use ES6 default parameters for fallbacks. Use the rest operator ...rest to pass through unknown HTML attributes.
    DEFAULTS & REST
    // --- App.jsx (Parent) ---
    import React from 'react';
    import Badge from './Badge';
    
    const App = () => {
      return (
        <div className="app">
          {/* Uses default variant and count */}
          <Badge>Default</Badge>
          
          {/* Passes custom props and HTML attributes via rest */}
          <Badge variant="danger" count={5} id="alert-badge" title="Hover me">
            Alert
          </Badge>
        </div>
      );
    };
    
    // --- Badge.jsx (Child) ---
    const Badge = ({ variant = 'primary', count = 0, children, ...rest }) => {
      return (
        <span className={`badge badge-${variant}`} {...rest}>
          {children}
          {count > 0 && <span className="count">{count}</span>}
        </span>
      );
    };
    
    export default App;
    ยฉ 2026 ยท FixWins.com
    06 / 07
    โš› FixWins.com
    CH05-S07 โœ“

    ๐ŸŽฏ Props mastered!

    You now know how to pass Primitives, Objects, Functions, and use the children prop to build composable React UIs.
    Next: Custom Hooks for Reusable Logic

    Data flows down Functions flow up Composition via children
    โ–ถ

    Next: Custom Hooks

    Reusable state logic

    ๐Ÿ“

    Previous: Event Handling

    onClick, onChange, etc.

    ยฉ 2026 ยท FixWins.com
    07 / 07
    01 / 07