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;








0















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',
]









share|improve this question



















  • 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

















0















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',
]









share|improve this question



















  • 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













0












0








0


0






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',
]









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 the id?

    – Dan
    Mar 22 at 9:01












  • 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







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












2 Answers
2






active

oldest

votes


















0














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));





share|improve this answer

























  • 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












  • 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


















0














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;








share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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));





    share|improve this answer

























    • 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












    • 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















    0














    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));





    share|improve this answer

























    • 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












    • 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













    0












    0








    0







    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));





    share|improve this answer















    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));






    share|improve this answer














    share|improve this answer



    share|improve this answer








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












    • 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











    • 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













    0














    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;








    share|improve this answer



























      0














      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;








      share|improve this answer

























        0












        0








        0







        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;








        share|improve this answer













        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;









        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 9:09









        ASliceOfBreadASliceOfBread

        13




        13



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript