1

I am using prime reacts component library. I'm trying to use the calendar component https://primereact.org/calendar/ but can not figure out how to set the default value (initial value) of the calendar. I tried creating a hardcoded state but it just wont display, it will only display when I pick a date on the calendar. It wont even display if I make the actual value prop in the Calendar "02/01/2023". I even tried different formats. Any help is greatly appreciated.

const EventForm = (props) => {
const [start, setStart] = useState('02/01/2023')

return (
  <>
    <div className="field">
      <span className="p-float-label">
        <Calendar
          name="start"
          value={start}
          onChange={(e) => handleChange(e)}
        />
      <label>Start</label>
      </span>
    </div>
  </>
)}

export default EventForm
Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
Katherine Pacheco
  • 339
  • 3
  • 7
  • 24

1 Answers1

0

You have to use a Date object not a String.

const [start, setStart] = useState(new Date())
Melloware
  • 10,435
  • 2
  • 32
  • 62