Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

0

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

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!