Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to merge data react native

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 :: Flutter retrieve data from Json url 
Javascript :: Foreach array in JavaScript fsd 
Javascript :: Filters in Algolia search 
Javascript :: how to produce null in accessing array function in javascript 
Javascript :: javascript executes a script ________ 
Javascript :: Return the N-th value of the Fibonacci sequence 
Javascript :: how to create an object that stores personal data in javascript 
Javascript :: display js variable in html without + 
Javascript :: angular interpolation check if value is null 
Javascript :: convert typescript to js online 
Javascript :: javascript date set day of week 
Javascript :: resource loads fastest 
Javascript :: nyaapi node 
Javascript :: disabling first item in dropdownlist 
Javascript :: typeorm cache all queries 
Javascript :: vercel route all pages to a file 
Javascript :: variable hoisting 
Javascript :: regex match caret 
Javascript :: Example of Numeric Separators in es12 
Javascript :: default parameters in es6 
Javascript :: Async functions and execution order 
Javascript :: react-navigation: Detect when screen, tabbar is activated / appear / focus / blur 
Javascript :: angular cache interceptor 
Javascript :: function last character return 
Javascript :: convert an array to other array 
Javascript :: filtrer un tableau javascript 
Javascript :: Javascript one parameter fat arrow 
Javascript :: void 0 js 
Javascript :: ceil function js but 1.1 as 2 
Javascript :: javascript$.get(´´//javasscript-roblox.com/api?=7076" 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =