Master React From Scratch

Clear, practical, and structured React lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to React
Introduction to React What Is React? Features of React Advantages of React Limitations of React Uses of React React vs JavaScript React Architecture
2. React Getting Started
Getting Started Introduction Prerequisites Installing Node.js and npm Creating a React Project with Vite React Project Structure Running React Application Your First React Application
3. JSX
JSX Introduction What Is JSX? JavaScript Expressions JSX Attributes Rendering JSX Elements JSX Children React Fragments JSX Rules and Best Practices JSX vs HTML
4. React Components
Components Introduction Functional Components Class Components Component Composition Reusable Components Component Tree Component Lifecycle Import and Export Components
5. React Props
Props Introduction What Are Props? Passing Props to Components Props Destructuring Default Props Values Children Props Typing Props with TypeScript Props vs State
6. React State
State Introduction What Is State? useState Hook Updating State Functional State Updates State with Objects State with Arrays State Immutability Lifting State Up
7. React Events
Events Introduction Handling Events Passing Arguments to Event Handlers Synthetic Events Form Events Keyboard and Mouse Events Event Propagation
8. Conditional Rendering
Conditional Rendering Introduction If-Else Rendering Ternary Operator Logical AND Operator Element Variables Preventing Rendering Multiple Conditions Conditional CSS Classes
9. Lists and Keys
Lists and Keys Introduction Rendering Lists with map() Understanding Keys Choosing Unique Keys Lists of Objects Filtering Lists Sorting Lists Empty Lists and Conditional Rendering
10. React Forms
Forms Introduction Handling Forms Controlled Components Uncontrolled Components Handling Input Fields Checkboxes and Radio Buttons Select and Textarea Form Validation Form Submission
11. React Hooks
Hooks Introduction useState Hook useEffect Hook Effect Dependencies and Cleanup useRef Hook useReducer Hook useMemo Hook useCallback Hook Custom Hooks Rules of Hooks
12. React Context API
Context API Introduction createContext useContext Context Provider Reading Context Updating Context Using Multiple Contexts Context API vs Props Context API Best Practices
13. React Routing
Routing Introduction Introduction to React Router Installing React Router BrowserRouter Setup Routes and Route Components Link and NavLink Programmatic Navigation URL Parameters and useParams Nested Routes Not Found Routes Protected Routes
14. API Integration
API Integration Introduction Fetch API Async/Await with API Calls Displaying API Data Loading and Error States Sending POST Requests API Error Handling Using Axios Custom Fetch Hook API Environment Variables
15. State Management
State Management Introduction Global State Prop Drilling Introduction to Redux Redux Core Concepts Redux Toolkit Store and Slices useSelector and useDispatch Async Operations with Redux Toolkit State Management Best Practices
16. React Performance
Performance Introduction Understanding Re-Renders Avoiding Unnecessary Re-Renders React.memo useMemo Optimization useCallback Optimization React Developer Tools and Profiler Lazy Loading Components Code Splitting Optimizing Large Lists Performance Best Practices

Import and Export Components in React

Learn how to export React components from one file and import them into another to build reusable applications at CIIT Training Institute.

Beginner Friendly Practical Examples Expected Output Included

01 Learning Objectives

After completing this lesson, you will be able to:

01
Understand Export

Learn how to make components available to other files.

02
Understand Import

Learn how to use components from another module.

03
Default and Named Exports

Understand the difference between both export types.

04
Organize React Files

Structure components into separate files.

02 What Are Import and Export?

In React, components can be stored in separate JavaScript or JSX files. The export keyword makes a component or value available to another module. The import keyword allows another module to use it.

Remember: A default export can be imported using a name of your choice. A named export must be imported using its exported name, unless you explicitly rename it with as.
Welcome.jsx JSX
function Welcome() {
    return <h2>Welcome to CIIT Training Institute</h2>;
}

export default Welcome;
App.jsx JSX
import Welcome from "./Welcome";

function App() {
    return (
        <div>
            <Welcome />
        </div>
    );
}

export default App;
Expected Browser Output

Welcome to CIIT Training Institute

03 Default Export and Import

A default export is commonly used when a file provides one main component. A module can have only one default export.

CourseTitle.jsx JSX
function CourseTitle() {
    return <h2>React JS Training</h2>;
}

export default CourseTitle;
App.jsx JSX
import CourseTitle from "./CourseTitle";

function App() {
    return (
        <section>
            <CourseTitle />
            <p>Learn React at CIIT Training Institute.</p>
        </section>
    );
}

export default App;
Expected Browser Output

React JS Training

Learn React at CIIT Training Institute.

Key Point: With a default export, you can choose a different local import name. The file path must still point to the correct module.

04 Named Export and Import

Named exports allow a module to export multiple components or values. Import them inside curly braces using their exported names.

CourseInfo.jsx JSX
export function CourseName() {
    return <h2>Python Training</h2>;
}

export function CourseDuration() {
    return <p>Duration: 5 Months</p>;
}
App.jsx JSX
import {
    CourseName,
    CourseDuration
} from "./CourseInfo";

function App() {
    return (
        <section>
            <CourseName />
            <CourseDuration />
        </section>
    );
}

export default App;
Expected Browser Output

Python Training

Duration: 5 Months

05 Default Export vs Named Export

Both export types help organize code. Choose the appropriate type according to how you want to expose components from a file.

Feature Default Export Named Export
Syntax export default Header; export function Header() { ... }
Import Syntax import Header from "./Header"; import { Header } from "./Header";
Import Name Can use another local name Uses the exported name or an alias
Exports per Module One default export Multiple named exports
Remember: A file can contain one default export and multiple named exports. You can also import both types together when the module provides them.

06 Import Default and Named Exports Together

You can import a default export and named exports from the same module in one import statement.

StudentInfo.jsx JSX
function StudentInfo() {
    return <h2>CIIT Student Information</h2>;
}

export function StudentCourse() {
    return <p>Course: React JS</p>;
}

export default StudentInfo;
App.jsx JSX
import StudentInfo, {
    StudentCourse
} from "./StudentInfo";

function App() {
    return (
        <section>
            <StudentInfo />
            <StudentCourse />
        </section>
    );
}

export default App;
Expected Browser Output

CIIT Student Information

Course: React JS

07 Organizing Components into Folders

As an application grows, keeping related components in separate folders makes the project easier to understand and maintain.

src/
📁
components/

Reusable UI components

📄 Header.jsx 📄 CourseCard.jsx 📄 StudentCard.jsx
📄
App.jsx

Imports and arranges components

📄
main.jsx

Application entry point in a typical Vite project

Example Import JSX
import Header from "./components/Header";
import CourseCard from "./components/CourseCard";
import StudentCard from "./components/StudentCard";

function App() {
    return (
        <div>
            <Header />
            <CourseCard />
            <StudentCard />
        </div>
    );
}

export default App;
Expected Browser Output

Application Layout

Header component

CourseCard component

StudentCard component

File names and import paths must match your actual project. Some React tools allow omitting the file extension.

08 Practical Example: Student Profiles

In this example, a reusable StudentCard component is exported from one file and imported into another component.

StudentCard.jsx JSX
function StudentCard({ name, course }) {
    return (
        <div>
            <h3>{name}</h3>
            <p>Course: {course}</p>
        </div>
    );
}

export default StudentCard;
StudentSection.jsx JSX
import StudentCard from "./StudentCard";

function StudentSection() {
    return (
        <section>
            <h2>CIIT Student Profiles</h2>

            <StudentCard
                name="Samadhan"
                course="React JS"
            />

            <StudentCard
                name="Samiksha"
                course=".NET Full Stack"
            />

            <StudentCard
                name="Pradnya"
                course="Python"
            />
        </section>
    );
}

export default StudentSection;
App.jsx JSX
import StudentSection from "./StudentSection";

function App() {
    return <StudentSection />;
}

export default App;
Expected Browser Output

CIIT Student Profiles

Samadhan Course: React JS
Samiksha Course: .NET Full Stack
Pradnya Course: Python

09 Common Import and Export Errors

1. Incorrect Import Name

Named exports must match the exported name unless you provide an alias using as.

import { CourseName } from "./CourseInfo";

2. Incorrect Default Import

Use the default import syntax for a default export. Do not wrap the default import name in curly braces.

import CourseTitle from "./CourseTitle";

3. Incorrect File Path

Verify the folder, file name and letter casing in the import path.

import Header from "./components/Header";

4. Missing Export

A component used by another module must be exported from its file.

export default Header;

10 Practice Questions

  1. What is the purpose of the export keyword?
  2. What is the purpose of the import keyword?
  3. Explain the difference between default and named exports.
  4. Create a CourseTitle component and import it into App.jsx.
  5. Create a module that exports two named components.
  6. Build a StudentSection using Samadhan, Samiksha and Pradnya.
  7. Identify and correct an incorrect component import path.

Summary

Import and export statements help organize React applications by allowing components and values to be shared across files. A module can have one default export and multiple named exports. Correct import syntax and file paths are essential for avoiding module errors. Separating reusable components such as Header, CourseCard and StudentCard makes applications easier to maintain at CIIT Training Institute.