A simple and interactive counter application built using React.js and Vite. It allows users to increment, decrement, and reset a numerical counter through an intuitive user interface.
This project demonstrates the fundamentals of React, particularly functional components, state management using the useState Hook, and event handling.
🌐 Live Demo: Counter App
- Increment Counter: Increase the counter value by 1 with a single click.
- Decrement Counter: Decrease the counter value by 1.
- Reset Counter: Reset the counter value to its initial state (0).
- Real-Time Updates: The displayed counter value updates immediately whenever a button is clicked.
- React State Management: Uses React's
useStateHook to manage and update the counter value. - Interactive UI: Simple and intuitive interface with clearly distinguishable buttons.
- Responsive Styling: CSS styling with a media query to adapt the layout for different screen sizes.
- Clean Design: Minimal interface with a centered counter container, rounded buttons, and subtle shadows.
| Technology | Purpose |
|---|---|
| React.js | Building the user interface |
| JavaScript (ES6+) | Application logic and event handling |
| CSS3 | Styling and responsive design |
| Vite | Development server and build tool |
| ESLint | Code quality and linting |
| Git | Version control |
| GitHub | Source code hosting |
| Vercel | Deployment and hosting |
Follow these instructions to run the project locally.
Make sure you have the following installed:
- Node.js (compatible with Vite 8)
- npm (comes bundled with Node.js)
- Git
git clone https://github.com/kavinanandr/counter.gitcd counternpm installThis installs the required dependencies, including React, React DOM, Vite, and ESLint.
npm run devVite will start the local development server.
Open the URL displayed in your terminal (usually):
http://localhost:5173/
To generate an optimized production build, run:
npm run buildThe production-ready files will be generated inside the dist/ directory.
To preview the production build locally:
npm run previewTo check the project for linting issues:
npm run lint
counter/
│
├── public/ # Public static files
│
├── src/ # Main application source code
│ ├── assets/ # Static assets used by the application
│ │ └── favicon.png # Application icon asset
│ │
│ ├── App.jsx # Main counter component and application logic
│ ├── index.css # Global styles and responsive styling
│ └── main.jsx # React application entry point
│
├── .gitignore # Specifies files and directories Git should ignore
├── eslint.config.js # ESLint configuration for code quality checks
├── index.html # Main HTML template loaded by the browser
├── package.json # Project metadata, dependencies and npm scripts
├── package-lock.json # Locks dependency versions
├── README.md # Project documentation
├── vercel.json # Vercel deployment configuration
└── vite.config.js # Vite configuration
The application uses React's useState Hook to maintain the counter value.
const [counter, setCounter] = useState(0);counterstores the current counter value.setCounterupdates the counter state.0is the initial counter value.
const increment = () => {
setCounter(counter + 1);
};Increases the counter value by one.
const decrement = () => {
setCounter(counter - 1);
};Decreases the counter value by one.
const reset = () => {
setCounter(0);
};Resets the counter value to zero.
React automatically re-renders the component when its state changes, ensuring that the updated counter value is displayed.
This project was developed to practice and understand the fundamentals of React development.
Key concepts explored:
- Understanding React functional components.
- Managing component state using the
useStateHook. - Handling user interactions through event handlers.
- Updating the UI dynamically through state changes.
- Understanding React's component rendering process.
- Organizing a React project using Vite.
- Applying CSS for layout, styling, and responsiveness.
- Running development and production builds.
Potential enhancements for future versions:
- Add customizable increment and decrement values.
- Prevent the counter from going below zero (optional setting).
- Add a history of previous counter operations.
- Implement local storage to preserve the counter value after refreshing.
- Introduce animated transitions when the counter changes.
Kavin Anand
- GitHub: @kavinanandr
- Repository: counter
- Live Application: Counter App
This project is open-source. No license has currently been specified for this repository.
⭐ If you find this project useful, consider giving it a star!