Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda