Building a React App from Scratch with Vite & Redux

1. React.js Overview

React.js is a JavaScript library for building user interfaces, primarily for single-page applications. It allows developers to create reusable UI components.

Key Features of React

  • Component-based architecture

  • Virtual DOM for efficient rendering

  • State and Props for managing data

  • Hooks for managing state and side effects


2. Vite Overview

Vite is a modern front-end build tool that improves the development experience by providing:

  • Fast server start-up with ES modules

  • Hot Module Replacement (HMR) for faster updates

  • Optimized production builds


3. Redux Overview

Redux is a state management library that helps manage global state in a predictable way.

Key Concepts

  • Store: Holds the application state.

  • Actions: Describe state changes.

  • Reducers: Handle actions and modify state.

  • Dispatch: Sends actions to the store.


Building a React App from Scratch with Vite & Redux

We’ll create a simple counter app using React, Vite, and Redux.


Step 1: Create a React App using Vite

Open your terminal and run:

Navigate into the project folder:

Install dependencies:

Start the development server:


Step 2: Install Redux Toolkit

Redux Toolkit simplifies Redux implementation.


Step 3: Setup Redux Store

Create a folder store inside src and a file store.js inside it.

📌 src/store/store.js

Step 4: Create a Counter Slice

Create a file counterSlice.js inside the store folder.

📌 src/store/counterSlice.js


Step 5: Provide the Redux Store to React

Wrap the App component with Provider in main.jsx.

📌 src/main.jsx


Step 6: Create Counter Component

📌 src/components/Counter.jsx


Step 7: Use Counter Component in App

📌 src/App.jsx


Step 8: Run the App

Start the development server again if needed:

Go to http://localhost:5173/, and you should see the counter app working.

Last updated