How to push to object in React Native?

Viewed 48

I know I'm probably overlooking something obvious, but when trying to push to an existing object, nothing happens. It will log up to "Makes it here".

const storeData = async (todo) => {
  try {
    const getCurrentTodos = await AsyncStorage.getItem('todos');
    let currentTodos = JSON.parse(getCurrentTodos);

    if(currentTodos) {
      currentTodos = [];
    }

    console.log('Makes it here', currentTodos)
    currentTodos.push(todo);
    console.log('Does not make it here', currentTodos)
  } catch(e) {
    // save error
  }

  console.log('Makes it here.')
}

This is the currentTodos obj

Object {
  "description": "none",
  "title": "Test 1",
}

This is the todo obj

Object {
  "description": "none",
  "title": "Test 2",
}
0 Answers
Related