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

192
Visualizações
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
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