Search code examples
arraysreact-nativeasyncstorage

React Native - 'target. value not working on mobile'


Greetings fellow humans,

I have a small problem with this little app that is just supposed to store and display data: https://snack.expo.dev/@vevlex/nullnotanobject

When I test this dircetly from my pc (I scan the QR code in my cmd window) on an ipad, the app boots fine but the data is not saved when re-running the app or when sending a job to another window (The "To Do" button on the right that shows up after you check a job).

When I run it from Expo, I get this error: null is not an object (evaluating 'jobs.map'

So I assume I'm doing something wrong with the saving / loading, or when actually writing the map, but I'm not sure, and I don't know how to approach this problem on my own.

Can anyone help me? Please and thank you.

Update: var temp1 is not being set, as the alert here returns "Unidentified" even tho I just define it in the previous line. This only happens on iOS and android, it works fine on the web sim. Can anyone explain this?

<TextInput
                  style={s.jobInput}
                  onChange={(e) => {
                    var temp1 = e.target.value;
                    alert(temp1)
                    setJobs((currentJobs) =>
                      produce(currentJobs, (v) => {
                        v[index].address = temp1;
                      })
                    );
                    saveItem();
                    
                  }}
                  value={j.address}
                  placeholder="Address"
                />

Solution

  • Ok after finding out what I stated in the update I searched a bit more and found out that on mobile you should use onChangeText rather than just onChange.