Home > Mobile >  React: How to send data to parent as an object and how to use it?
React: How to send data to parent as an object and how to use it?

Time:09-12

I made a date calculation and I stored year, month & day values in an object and I wanna send this object to the parent App.js and then send that data to my other child component Modal.js as a prop and show it in the popup message (the calculation result) but while receiving the data in the App.js I don't know how to use it / store it and send it to the other component.

UserAgeForm.js

const onSubmitHandler = (e) => {
    e.preventDefault();
    const calcAge = () => {
        let calcYear;
        let calcMonth;
        let calcDay;

        if (currentDate < birthDay || currentMonth < birthMonth) {
            calcDay = currentDate   currentMonthDays - birthDay;
            calcMonth = currentMonth   11 - birthMonth;
            calcYear = currentYear - 1 - birthYear;
        } else {
            calcDay = currentDate - birthDay;
            calcMonth = currentMonth - birthMonth;
            calcYear = currentYear - birthYear;
        }
        //            
  • Related