React Native AsyncStorage not overwriting data Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!Hide keyboard in react-nativeWhat is the difference between using constructor vs getInitialState in React / React Native?What is the difference between React Native and React?React Native AsyncStorage returns promise instead of valueAsyncStorage React Native save an ArrayAsyncStorage.getItem returning undefined when using fetch - React-NativeAsyncStorage doesnt return anythingReact Native - Nested array in AsyncStorageActions must be plain objects. Use customer middleware for async actions in React NativeReact-native: undefined is not an object
What to do with chalk when deepwater soloing?
Why was the term "discrete" used in discrete logarithm?
What is the meaning of the new sigil in Game of Thrones Season 8 intro?
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
If a contract sometimes uses the wrong name, is it still valid?
Why light coming from distant stars is not discreet?
How do I stop a creek from eroding my steep embankment?
Using et al. for a last / senior author rather than for a first author
How to Merge Multiple Columns in to Two Columns based on Column 1 Value?
How does debian/ubuntu knows a package has a updated version
How to call a function with default parameter through a pointer to function that is the return of another function?
Is the Standard Deduction better than Itemized when both are the same amount?
When do you get frequent flier miles - when you buy, or when you fly?
Why aren't air breathing engines used as small first stages
Book where humans were engineered with genes from animal species to survive hostile planets
Why did the IBM 650 use bi-quinary?
Output the ŋarâþ crîþ alphabet song without using (m)any letters
How to find all the available tools in mac terminal?
What's the purpose of writing one's academic biography in the third person?
How to run gsettings for another user Ubuntu 18.04.2 LTS
How to find out what spells would be useless to a blind NPC spellcaster?
Why is "Consequences inflicted." not a sentence?
Error "illegal generic type for instanceof" when using local classes
Is it true that "carbohydrates are of no use for the basal metabolic need"?
React Native AsyncStorage not overwriting data
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!Hide keyboard in react-nativeWhat is the difference between using constructor vs getInitialState in React / React Native?What is the difference between React Native and React?React Native AsyncStorage returns promise instead of valueAsyncStorage React Native save an ArrayAsyncStorage.getItem returning undefined when using fetch - React-NativeAsyncStorage doesnt return anythingReact Native - Nested array in AsyncStorageActions must be plain objects. Use customer middleware for async actions in React NativeReact-native: undefined is not an object
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to make an app and I have a few objects in an array which I use AsyncStorage for. I need to change one element of an object but if I try changing it, it doesn't keep those changes.
My code:
save = async () => {
this.state.dataSource.notes = this.state.text;
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
The this.state.text
stores the value of the text input.
The this.state.dataSource
stores the array of objects.
Both of these work like they should.
The array looks like this:
Array = [
item =
id: 'id',
name: 'name',
brand: 'brand',
inname: 'inname',
chosenWeekDay: 'week day',
androidDate: 'date for android',
chosenAndroidTime: 'time for android',
notes: 'notes in a string',
]
arrays react-native object mobile asyncstorage
add a comment |
I am trying to make an app and I have a few objects in an array which I use AsyncStorage for. I need to change one element of an object but if I try changing it, it doesn't keep those changes.
My code:
save = async () => {
this.state.dataSource.notes = this.state.text;
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
The this.state.text
stores the value of the text input.
The this.state.dataSource
stores the array of objects.
Both of these work like they should.
The array looks like this:
Array = [
item =
id: 'id',
name: 'name',
brand: 'brand',
inname: 'inname',
chosenWeekDay: 'week day',
androidDate: 'date for android',
chosenAndroidTime: 'time for android',
notes: 'notes in a string',
]
arrays react-native object mobile asyncstorage
1
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using theid
?
– Dan
Mar 22 at 9:01
add a comment |
I am trying to make an app and I have a few objects in an array which I use AsyncStorage for. I need to change one element of an object but if I try changing it, it doesn't keep those changes.
My code:
save = async () => {
this.state.dataSource.notes = this.state.text;
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
The this.state.text
stores the value of the text input.
The this.state.dataSource
stores the array of objects.
Both of these work like they should.
The array looks like this:
Array = [
item =
id: 'id',
name: 'name',
brand: 'brand',
inname: 'inname',
chosenWeekDay: 'week day',
androidDate: 'date for android',
chosenAndroidTime: 'time for android',
notes: 'notes in a string',
]
arrays react-native object mobile asyncstorage
I am trying to make an app and I have a few objects in an array which I use AsyncStorage for. I need to change one element of an object but if I try changing it, it doesn't keep those changes.
My code:
save = async () => {
this.state.dataSource.notes = this.state.text;
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
The this.state.text
stores the value of the text input.
The this.state.dataSource
stores the array of objects.
Both of these work like they should.
The array looks like this:
Array = [
item =
id: 'id',
name: 'name',
brand: 'brand',
inname: 'inname',
chosenWeekDay: 'week day',
androidDate: 'date for android',
chosenAndroidTime: 'time for android',
notes: 'notes in a string',
]
arrays react-native object mobile asyncstorage
arrays react-native object mobile asyncstorage
edited Mar 22 at 8:33
ASliceOfBread
asked Mar 22 at 8:17
ASliceOfBreadASliceOfBread
13
13
1
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using theid
?
– Dan
Mar 22 at 9:01
add a comment |
1
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using theid
?
– Dan
Mar 22 at 9:01
1
1
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using the
id
?– Dan
Mar 22 at 9:01
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using the
id
?– Dan
Mar 22 at 9:01
add a comment |
2 Answers
2
active
oldest
votes
You need to target a specific object in your dataSource
array
let dataSource, text = this.state;
const yourSpecfiicIndex = 12; // whatever
dataSource[yourSpecfiicIndex].notes = text;
//...
await AsyncStorage.setItem('medicines', JSON.stringify(dataSource));
if I console.log clonedDataSource it gives meObject "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
add a comment |
I found a solutions:
save = async () =>
this.changeNotes(this.state.id, this.state.text);
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
changeNotes( value, note )
for (var i in this.state.dataSource)
if (this.state.dataSource[i].id == value)
this.state.dataSource[i].notes = note;
break;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295450%2freact-native-asyncstorage-not-overwriting-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to target a specific object in your dataSource
array
let dataSource, text = this.state;
const yourSpecfiicIndex = 12; // whatever
dataSource[yourSpecfiicIndex].notes = text;
//...
await AsyncStorage.setItem('medicines', JSON.stringify(dataSource));
if I console.log clonedDataSource it gives meObject "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
add a comment |
You need to target a specific object in your dataSource
array
let dataSource, text = this.state;
const yourSpecfiicIndex = 12; // whatever
dataSource[yourSpecfiicIndex].notes = text;
//...
await AsyncStorage.setItem('medicines', JSON.stringify(dataSource));
if I console.log clonedDataSource it gives meObject "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
add a comment |
You need to target a specific object in your dataSource
array
let dataSource, text = this.state;
const yourSpecfiicIndex = 12; // whatever
dataSource[yourSpecfiicIndex].notes = text;
//...
await AsyncStorage.setItem('medicines', JSON.stringify(dataSource));
You need to target a specific object in your dataSource
array
let dataSource, text = this.state;
const yourSpecfiicIndex = 12; // whatever
dataSource[yourSpecfiicIndex].notes = text;
//...
await AsyncStorage.setItem('medicines', JSON.stringify(dataSource));
edited Mar 22 at 8:54
answered Mar 22 at 8:27
Hend El-SahliHend El-Sahli
1,2181314
1,2181314
if I console.log clonedDataSource it gives meObject "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
add a comment |
if I console.log clonedDataSource it gives meObject "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
if I console.log clonedDataSource it gives me
Object "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
if I console.log clonedDataSource it gives me
Object "0": Object "brand": "Ziagen", "chosenDate": "2019-03-22T08:36:24.024Z", "chosenWeekDay": "Ma", "id": 104, "inname": "day", "name": "Abacavir", "notes": "Type je notities hier....", , "notes": "Test",
– ASliceOfBread
Mar 22 at 8:38
It has been parsed like this:
const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
It has been parsed like this:
const value = await AsyncStorage.getItem('medicines'); if(value !== null) const allMeds = JSON.parse(value); this.setState( dataSource: allMeds );
– ASliceOfBread
Mar 22 at 8:48
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
I'm sorry ... I was wrong ... your datasource is actually an array not an object, you need to access a specific index ... revise the answer plz
– Hend El-Sahli
Mar 22 at 8:51
add a comment |
I found a solutions:
save = async () =>
this.changeNotes(this.state.id, this.state.text);
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
changeNotes( value, note )
for (var i in this.state.dataSource)
if (this.state.dataSource[i].id == value)
this.state.dataSource[i].notes = note;
break;
add a comment |
I found a solutions:
save = async () =>
this.changeNotes(this.state.id, this.state.text);
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
changeNotes( value, note )
for (var i in this.state.dataSource)
if (this.state.dataSource[i].id == value)
this.state.dataSource[i].notes = note;
break;
add a comment |
I found a solutions:
save = async () =>
this.changeNotes(this.state.id, this.state.text);
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
changeNotes( value, note )
for (var i in this.state.dataSource)
if (this.state.dataSource[i].id == value)
this.state.dataSource[i].notes = note;
break;
I found a solutions:
save = async () =>
this.changeNotes(this.state.id, this.state.text);
try
AsyncStorage.clear();
await AsyncStorage.setItem('medicines', JSON.stringify(this.state.dataSource));
catch (error)
console.log('error');
this.setModalVisible(!this.state.modalVisible);
changeNotes( value, note )
for (var i in this.state.dataSource)
if (this.state.dataSource[i].id == value)
this.state.dataSource[i].notes = note;
break;
answered Mar 22 at 9:09
ASliceOfBreadASliceOfBread
13
13
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295450%2freact-native-asyncstorage-not-overwriting-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
How are you selecting the specific item in AsyncStorage you want to change? For example, are you using the
id
?– Dan
Mar 22 at 9:01