6
6
Create a component Counter with A state variable count initialized to 0. Create Buttons to increment and decrement
the count. Simulate fetching initial data for the Counter component using useEffect (functional component) or
componentid count (class component). Extend the Counter component to Double the count value when a button is
clicked. Reset the count to 0 using another button.
Steps for reactjs:
Old approach
================
First install GIT
Ensure you are installing a compatible version of React, such as react@18. Run the following command to create the
React app with a specific version:
npx create-react-app counter-app
Options to Select:
1.Would you like to use TypeScript? No (Choose "Yes" if you want TypeScript, but if you prefer simplicity, select
"No").
2.Would you like to use ESLint? Yes (Recommended for maintaining code quality, especially in team projects).
3.Would you like to use Tailwind CSS? No (Select "Yes" if you plan to style your app using Tailwind CSS, but it's
unnecessary for this Counter Experiment).
4.Would you like your code inside a src/ directory? Yes (This organizes your files better, making the project
structure clean and scalable).
5.Would you like to use App Router? (recommended) Yes (This uses the latest Next.js routing features introduced
in version 13).
Would you like to use Turbopack for next dev? Yes (Recommended for faster development builds; it's
experimental but stable for many use cases).
6.Would you like to customize the import alias (@/* by default)? No (Stick with the default unless you have
specific aliasing requirements).
TypeScript? No
ESLint? Yes
Tailwind CSS? No
Code inside `src/`? Yes
App Router? Yes
Turbopack for `next dev`? Yes
Import alias customization? No
Procedure
1.put Counter.jsx code In the folder like by creating Counter.js in src/app/Counter.js. and also add 'use client'; as first
line in this file.
2.Moify the page.js content with src/App.Jsx by removing importing of App.jsx
3.create a folder like mkdir 6
4.cd 6
5.npm create vite@latest count
6.npm install
7.under src folder
8.App.jsx
9.Statemgt.jsx
11.=================
12.Statemgtclass.jsx