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

202
Vistas
React throws "invalid hook error" when initializing Date() in a functional component

React throws the error below when trying to initialize the Date object in a functional component made with the "rfc"-snippet. I have no hooks in the component. let dateObj = new Date() is the only thing added besides the snippet.

I have checked my React-versions and tried restarting the server. I used create-react-app to create my React project.

Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component.

import React from 'react'

function Date() {

  let date = new Date()

  return (
    <div>Date</div>
  )
}

export default Date

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try changing the name of your function.

import React from 'react'

function CurrentDate() {

  let date = new Date()

  return (
    <div>Date</div>
  )
}

export default CurrentDate

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