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

279
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!