Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to merge data rn

const USER_1 = {
  name: 'Tom',
  age: 20,
  traits: {
    hair: 'black',
    eyes: 'blue'
  }
}

const USER_2 = {
  name: 'Sarah',
  age: 21,
  hobby: 'cars',
  traits: {
    eyes: 'green',
  }
}


mergeUsers = async () => {
  try {
    //save first user
    await AsyncStorage.setItem('@MyApp_user', JSON.stringify(USER_1))

    // merge USER_2 into saved USER_1
    await AsyncStorage.mergeItem('@MyApp_user', JSON.stringify(USER_2))

    // read merged item
    const currentUser = await AsyncStorage.getItem('@MyApp_user')

    console.log(currentUser)

    // console.log result:
    // {
    //   name: 'Sarah',
    //   age: 21,
    //   hobby: 'cars',
    //   traits: {
    //     eyes: 'green',
    //     hair: 'black'
    //   }
    // }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: loop featured image react wordpress api 
Javascript :: check version of 3rd package npm 
Javascript :: gitignore jsconfig 
Javascript :: Component on new window 
Javascript :: Scroll event throttling JS MDN 
Javascript :: how to get value from a label in javascript gtk 
Javascript :: execute shell command from html button node js 
Javascript :: c program to print triangle using recursion in javascript 
Javascript :: jasmine returnvalues example 
Javascript :: how can i add + buttons for expand and - button for collapse in react 
Javascript :: accèder data-id javascript 
Javascript :: Using a fallback if module loading fails 
Javascript :: cache blogposts for 24 hours react native 
Javascript :: npm init step by step 
Javascript :: crear un texto dinamicamente con javascript 
Javascript :: hex decode javascript 
Javascript :: create an array filled with 1 
Javascript :: counter random interval 
Javascript :: Example of String.prototype.replaceAll in es12 
Javascript :: Spread syntax in ES6 
Javascript :: google.translate.TranslateElement part of page 
Javascript :: red foreach loop 
Javascript :: react native helper packages 
Javascript :: javascript loob array 
Javascript :: for (var i = 0; i < 3; i++) { setTimeout(function() { console.log(i); }, 1000 + i); } 
Javascript :: node app not visible in browser aws ec2 
Javascript :: success and failure callback functions js 
Javascript :: initialize back4app 
Javascript :: discord.js anonymous channel 
Javascript :: atomic design with redux 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =