Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda