I'm beginner in ReactJS and I'm trying to save some dates fields.
By default, the dates are save in format yyyy-MM-dd, but when I able to send the date for the API the format should be in format dd/mm/yyyy.
I already try using .toLocaleDateString('pt-BR', {timeZone: 'UTC'});. But when I did that, return error:
The specified value "19/8/2020" does not conform to the required format, "yyyy-MM-dd".
Here's my code I put in CodeSandBox
And, here where I get the date values:
import React, { useState } from "react";
const NewUser = () => {
  const [data, setData] = useState({
    birthdate: "",
    admission_date: ""
  });
  const changeField = (field, value) => {
    const auxData = { ...data };
    auxData[field] = value;
    setData(auxData);
  };
  return (
    <div>
      <span>Born</span>
      <input
        id="birthdate"
        type="date"
        value={data.birthdate}
        onChange={(event) => changeField("birthdate", event.target.value)}
      />
      <div />
      <span>Admission Date</span>
      <input
        id="admission_date"
        type="date"
        value={data.admission_date}
        onChange={(event) => changeField("admission_date", event.target.value)}
      />
    </div>
  );
};
export default NewUser; 
     
    
