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

280
Visualizações
How can i input string data in object?

I'm trying to input text to innerState.feedType. but when i tried it says Cannot read property 'toString' of undefined How can i fix my code?

this is my code

     const [innerState, setInnerState] = useState<any>({
       feedType: 'bbong', 
        })


     const onChangeEtcfeedtype = useCallback((text) => {
          setInnerState( innerState['feedType'] = text)
       },[]);

        <TextInput
            placeholder="input."
            value={innerState.feedType}
            onChangeText={onChangeEtcfeedtype}
          />
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You need to add null-safety(?) operator, because state creates after render components. Also need to return new link on object for re-render component.

 const [innerState, setInnerState] = useState<any>({
   feedType: 'bbong', 
    })


 const onChangeEtcfeedtype = (text) => {
      setInnerState({...innerState, innerState.feedType: text});
   };

    <TextInput
        placeholder="input."
        value={innerState?.feedType}
        onChangeText={onChangeEtcfeedtype}
      />
about 4 years ago · Juan Pablo Isaza Relatório

0

I think this is how you should write it. About the error. It look like its not come from this part. It come from your <TextInput /> component and possiblely caused because what you doing with onChange event.

const [innerState, setInnerState] = useState<any>({
       feedType: 'bbong', 
     })


     const onChangeEtcfeedtype = useCallback((text) => {
          setInnerState({feedType: text})
       },[]);

        <TextInput
            placeholder="input."
            value={innerState.feedType}
            onChangeText={onChangeEtcfeedtype}
          />

Please do consider read these article:

https://xyproblem.info/

https://stackoverflow.com/help/how-to-ask

about 4 years ago · Juan Pablo Isaza Relatório

0

Here, innerState['feedType'] = text you are changing the state directly and then store it using the updater function, you should not change it directly.

You have innerState which is object and it contains feedType property. So, update a state you have to pass the object with the same key with new value.

Correct Way:

setInnerState({feedType: text})
about 4 years ago · Juan Pablo Isaza 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