Reputation: 308
I want to use current Date as a state in my component using useState hooks. So I made this...
import React, { useState } from "react";
import Navbar from "./components/Navbar/Navbar";
import Date from "./components/Date/Date";
import "./App.css";
const App = () => {
const [date, setDate] = useState(new Date());
return (
<div className="App">
<Navbar />
<Date selectedDate={date} />
</div>
);
};
export default App;
But it throws this error when I am setting my initial date as a new Date object.
Upvotes: 0
Views: 1802
Reputation: 53894
Your component is named Date
, like the Date
object you trying to use:
// Rename
import DateComponent from "./components/Date/Date";
// Will call the constructor of Date object
new Date();
Upvotes: 4