How to do crud operations in ReactJS ?
CRUD stands for Create, Read, Update, and Delete. In ReactJS everything is aligned in a form of a component and every component has its own way and feature to do so.
React js is one of the most used JavaScript libraries for frontend development. It’s very important to have the basic functionality of CRUD operations in with react-js. In this article, we don’t use any JSON-server or Axios for performing the CRUD operation. We will use a simple JavaScript object to do so.
For learning CRUD operation with ReactJS and NodeJS please refer to How to build a basic CRUD app with Node.js and ReactJS?
- Create: Creating a post or adding the table row, adding data into the webpage, or creating content.
- Read: Reading or retrieving data from web-page
- Update: Updating or editing existing content in the webpage
- Deleting: Deleting and removing the entry or content/post from the webpage
In this article, we will be learning to add the name and age of a user and perform CRUD operations into it.
Step 1: Setting up a project
Make sure you have node-js installed on your computer in order to create react app. Enter these commands for creating react app
npx create-react-app crud_app or yarn create react-app crud_app
After important installations, enter these commands on terminal/cmd
cd crud_app npm start or yarn start
This will start the application
Step 2: Project structure

You may get rid of other files like the logo, and other test files and delete them. Here are 4 files in components that are a core of this application in the source folder.
- array.js – This file is not a react file but a simple JavaScript object file (Our temporary data source). This object has 3 key-values id, name, and age.
- Create.js – This file consist logic for creating the post or adding a table row in out app.
- Edit.js – This file is responsible for editing the existing entry.
- Home.js – This file is a reading file and responsible for showing an information/data.
Step 3: Installing dependency
First of all download this dependency-
| Dependency | Installation command | Using purpose |
|---|---|---|
| React-Bootstrap | npm install react-bootstrap bootstrap@5.1.3 or yarn add react-bootstrap bootstrap@5.1.3 | Bootstrap is a CSS framework that react-router will help us for focusing on functionality rather than on CSS. |
| React Router Dom | npm install react-router-dom or yarn add react-router-dom | We use react router dom for various packages and modules like routers for routing, useNavigations and etc. |
Now, after installations, please create make a folder inside an src folder naming components. Then make 4 js files
Create.js Edit.js Home.js array.js
Step 4: Component files – creating files




Please Login to comment...