Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Do calculations with users input

I'm trying to do simple calculations with a new value in an updated state. I'm simply trying to divide a users input, with another number. I am a total beginner, so forgive me for the rooky question! Here's my code which isn't working for me. There are no errors, it's just not showing the resulting figure from the calculation -

import { useState } from "react";

const Counter = () => {
  const [area, setArea] = useState("");
  const newArea = () => {
    setArea(area.target.value);
  };
  const deckBoards = (newArea) => {
    (newArea / 0.145).toFixed(2);
  };
  return (
    <div label="Deck">
      <h2>Total area of deck</h2>
      Area
      <input
        placeholder="Enter area here"
        type="text"
        onChange={newArea}
        type="number"
      />
      <br />
      <h2>Deck boards</h2>Deck boards at 140mm wide : {deckBoards} lineal metres
    </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are missing event in the newArea function and DeckBoards needs to be area in JSx

Try this

import { useState } from "react";

const Counter = () => {
  const [area, setArea] = useState("");
  const deckBoards = (newArea) => {
    // it was missing return statement
    return (newArea / 0.145).toFixed(2);
  };
  const newArea = (e) => {
    const value = e.target.value;
    // Calculate here
    const calculated = deckBoards(value);
    // Update value
    setArea(calculated);
  };
 
  
  return (
    <div label="Deck">
      <h2>Total area of deck</h2>
      Area
      <input
        placeholder="Enter area here"
        type="text"
        onChange={newArea}
        type="number"
      />
      <br />
      <h2>Deck boards</h2>Deck boards at 140mm wide : {area} lineal metres
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!