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

200
Views
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 answers
Answer question

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 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!