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

191
Views
Function Passed in Object Attribute Not Recognised as Function

I am passing an options object into my SelectableUploadField component. One of the attributes of the items in the options object array is setter, which is a function.

When I try to call the setter function in the component, I get an error in the console saying options.setter is not a function and I'm not sure why.

Parent Component (that passes the props)

export default function ParentComponent() {
    const [documents, setDocuments] = useState({})

    function insertDocument(name, document) {
        setDocuments(prevState => ({
            ...prevState,
            [name]: document
        }))
    }

    return(
        <SelectableUploadField 
            options={[
                {
                    typeId: 'typeId1',
                    shortLabel: 'label1', 
                    title: 'title1', 
                    description: 'description 2', 
                    setter: insertDocument
                },
                {
                    typeId: 'typeId2',
                    shortLabel: 'label2', 
                    title: 'title2', 
                    description: 'description2', 
                    setter: insertDocument
                }
            ]}
            organisation={organisation}
        />
    )
}

Child Component (that throws the error)

function SelectableUploadField({ options }) {
    function handleClick() {
        options[0].setter(options.typeId, { name: 'myDocument', type: 'pdf' })
    }

    return(
        <button onClick={handleClick}>Click me</button>
    )
}

Why am I getting the error when options[index].setter is clearly a function?

about 4 years ago · Juan Pablo Isaza
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!