Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

0

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

almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda