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

84
Views
props value showing undefined while component initial load : React

I have a react component with props like below. what i am trying to do is to set the default values to the dropdown when page loads. i tried this with a dummy array and it works fine. but when i pass the array via props from another component the value is not setting.

export interface dropdownProps {
  list: [];
  defaultSelectedList: number[];
}

// const defaultSelectedList = [123, 432, 987]; **this works if i set a dummy array** 
   console.log(defaultSelectedList, 'test');

const Dropdown: FC<DropdownProps> = (props) => {
 const methods = useForm<{ dropdown: number[] }>({
    defaultValues: {
      dropdown: defaultSelectedList
    },
  });
}


  <FormProvider {...methods}>
        <MultiSelect
          name="dropdown"
          list={list}
        />
   </FormProvider>

when i console the value initially the value is undefined and then the value is set. i am guess this could be the issue. can anyone help me with this enter image description here

about 4 years ago · Santiago Trujillo
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!