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 :: arrow function with computed property vue 
Javascript :: downlaod file from website raect2 
Javascript :: bytes to uppercase hex javascript 
Javascript :: signing an msg.value transaction in ethersjs 
Javascript :: how to add class to only one selected row then remove it after selecting it again 
Javascript :: vscode redirect back 
Javascript :: jquery ui music player 
Javascript :: pass values and functions from a Child component to a Parent using a ref 
Javascript :: conditional statement for node on internet and node local server 
Javascript :: 4.6.3. Order of Operations¶ 
Javascript :: javascript activate file input 
Javascript :: playwrigth await browser 
Javascript :: how to display value in input field using innerText in js 
Javascript :: action creators in redux 
Javascript :: typeorm clear cache 
Javascript :: react get padding 
Javascript :: why android folder size is 500mb in react native 
Javascript :: Quitar objetos duplicados 
Javascript :: mindate from another datepicker 
Javascript :: Key and property shorthand in ES6 
Javascript :: react clearinterval outside of useefect 
Javascript :: find a node that match a spesific selector string in the paren 
Javascript :: maxscript saveMaxFile 
Javascript :: keep form values after submit javascript 
Javascript :: jshack1 
Javascript :: normalizedList.flatMap is not a function vue draggable 
Javascript :: javascript remove files name starts with 
Javascript :: javascript display block div 
Javascript :: { "rules": { ".read": true, ".write": true } } 
Javascript :: serve public folder express without file extension 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =