Back to Projects

React Calculator

December 27, 2024
ReactTypeScriptTailwind CSSInteractive

A fully functional calculator component built with React and Tailwind CSS.

This is a simple calculator application built as a "Hello World" project for my portfolio.

It demonstrates how interactive React components can be seamlessly embedded within MDX content. The calculator supports basic arithmetic operations including addition, subtraction, multiplication, and division.

Interactive Demo

Try it out below! This is a live React component running directly in this page.

0

How it works

The calculator logic is implemented using React's useState hook to manage the display value, current equation, and state transitions (e.g., whether the next input starts a new number).

  • State Management: Handles the current input and the running calculation.
  • Event Handling: Captures button clicks for numbers and operators.
  • Evaluation: Safely computes the result when = is pressed.