Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

281
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda