Trying to pass data between components

So… I’m a bit stumped here and any help would be great, guys.

I got some data that I’m trying to pass from a form component to another different component where I can do some validation. The data seems to be receiving all the data in the parent component up until I assign the userData prop.


import { TextField, Select, MenuItem, FormControl, InputLabel } from '@mui/material';
import {LoadingButton} from '@mui/lab'
import React, {useRef, useState} from 'react';
import SaveIcon from '@mui/icons-material/Save';
import '../styles/DataInput.css';
import ValidateUser from "./ValidateUser";

 export default function DataInput() {

    //State & Ref Hooks
    const [country, setCountry] = useState('');

    const handleCountryChange = (event) => setCountry(;

    const countryInputRef = useRef();
    const nameInputRef = useRef();
    const surnameInputRef = useRef();
    const birthdayInputRef = useRef();

    //Submit form, pass data to validator

    const formSubmissionHandler = event => {

        const rawUserData = {
            name: nameInputRef.current.value,
            surname: surnameInputRef.current.value,
            country: countryInputRef.current.value,
            birthday: birthdayInputRef.current.value

        <ValidateUser userData = {rawUserData}/>

        <form onSubmit={formSubmissionHandler}>
            <body className = "DataInput">

                    <div className = "Input-Boxes">

                        <div className = "Box-Name">
                                sx={{ input: { color: 'blue' }}} 
                                label = "Name"

                        <div className = "Box-Surname">
                                sx={{ input: { color: 'blue' }}} 
                                label = "Surname"

                        <div className = "Box-Country">
                            <FormControl variant="filled" sx={{ minWidth: 220 }}>
                                <InputLabel id="demo-simple-select-filled-label">Countries</InputLabel>

                                    labelId = "demo-simple-select-filled-label"
                                    id = "demo-simple-select-filled"
                                    label = "Countries"
                                    value = {country}
                                    onChange = {handleCountryChange}
                                    inputRef = {countryInputRef}

                                    <MenuItem value = {"Brazil"}> Brazil </MenuItem>
                                    <MenuItem value = {"Portugal"}> Portugal </MenuItem>

                        <div className = "Box-Birthday">
                                sx={{ input: { color: 'blue' }}} 
                                label = "Birthday"
                                inputRef = {birthdayInputRef}
                                type = "date"
                                InputLabelProps={{ shrink: true }} 


                    <div className = "Button-Save">
                            endIcon = {<SaveIcon />}
                            variant = "outlined"
                            type = "submit"


But then when I try to log it over the child component to see if data got there, I don’t get anything. Inspecting the props it shows up as " :any" instead of the data structure last seen over userData so I’m not sure if I’m missing some step along the way, if I’m trying to call the child component correctly or what.

Thanks in advance.


import React from 'react';

const ValidateUser = (props) => {




export default ValidateUser;

That’s not how you use React. You can’t just randomly put a component in a function and expect it to be called. Child components must be in the return function of the parent function.

1 Like

Thanks for the pointer. I went and changed how things were being assigned in order to be able to get the data into the scope and it’s working now.