2

I have a update form where I update the data that I get from backend. I have a date input field and I have a date which is in the 'yyyy-mm-dd' format. I want to show the date field with the date which I'm getting from backend as a default date on initial render. How do I acheive this in react js.

1 Answer 1

4

You could use moment library to convert your date to a moment obj and then use the format method to format it properly for the input field.

const Form = ({ yourDate }) => {
    const [date, setDate] = useState(moment(yourDate).format("YYYY-MM-DD"));

    return <input type="time" value={date} />
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.