Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
child component pass props to parent's useState -> returning undefined (react)

I want to put the props from the child component into the value of useState from the parent component, but it also comes with undefined. How can I not get undefined?

Child component

const FilterSelect = props => {
  const [filterUser, setFilterUser] = useState('all')

  const handleFilterUser = ({ target }) => {
    setFilterUser(target.value)
  }
  useEffect(() => {
    props.propFunction(filterUser)
  }, [filterUser])

  return (
    <Box sx={{ width: 120 }}>
      <FormControl fullWidth>
        <Select
          size="small"
          labelId="user-select-label"
          id="user-select"
          value={filterUser}
          label="filter"
          onChange={handleFilterUser}
        >
        </Select>
      </FormControl>
    </Box>
  )
}

parent component

import FilterSelect from './components/FilterSelect'

const UserList = () => {
  const [filterSelectOne, setFilterSelectOne] = useState('all')

  const highFunction = text => {
    setFilterSelectOne(text)
  }

  useEffect(() => {
    highFunction()
  }, [])

  console.log(filterSelectOne) // 'all', undefined

  return (
    <Box sx={{ width: '100%' }}>
      <Paper sx={{ width: '100%', mb: 2 }}>
        <FilterSelect propFunction={highFunction} />
      </Paper>
    </Box>
  )
}

enter image description here

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Remove the use effect where you call the highFunction with no parameters in the parent component

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda