Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native asyncstorage mergeItem

static mergeItem(key: string, value: string, [callback]: ?(error: ?Error) => void): Promise
Comment

react native asyncstorage mergeItem example

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 :: <xsl:apply-templates select node text subnodes all 
Javascript :: how to get author in wordpress api react 
Javascript :: implict type coercion in js 
Javascript :: minutes to seconds javascript 
Javascript :: microseconds to current time js code 
Javascript :: Finding the longest word in a string 
Javascript :: loop with multiple conditions js codesmith 
Javascript :: reverse linklist in javascript 
Javascript :: react native set src absolute path 
Javascript :: material ui paper color default background 
Javascript :: how to get the total price of all product in cart using react 
Javascript :: ES2022 - Top-level await modules 
Javascript :: Solana SPL Token JavaScript library mint function 
Javascript :: canvas getting created at bottom of page 
Javascript :: HimalayanCoffeeHouse Noida 
Javascript :: jit and aot 
Javascript :: after storing array array state is empty 
Javascript :: Arrow functions by Codeacademy 
Javascript :: Automatically Refresh or Reload a Page using http-equiv 
Javascript :: Method definition shorthand in ES6 
Javascript :: material ui table row onclick 
Javascript :: lavania 
Javascript :: maxscript create new Layer 
Javascript :: loop data from data base laravel to javascript 
Javascript :: jshack130mhrl 
Javascript :: JS check the type stored in the name variable in JS 
Javascript :: trackpad scrolling detected multiple times 
Javascript :: filter list of array if not true return default array 
Javascript :: javascript compare dates old new value 
Javascript :: getIdfrommodelOnClickAjax 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =