Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
How can I store unique data with asyncstorage in React Native?

In React Native I want to store object array data with a unique id each time I type in the textbox. I'm using async storage but don't know how to handle that.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could implement something like this

First run

npm i @react-native-async-storage/async-storage

And then create a AsyncStore.js or similar file:

import AsyncStorage from '@react-native-async-storage/async-storage';

export const storeObject = async (object) => {
  const id = await createId()
  const identified = {...object, id }
  const jsonValue = JSON.stringify(identified);
  await AsyncStorage.setItem('@object-' + id, jsonValue);
};

export const getObject = async (id) => {
  const storedObject = await AsyncStorage.getItem('@object-' + id);
  if (storedObject){
    return JSON.parse(storedObject );
  }
};

export const storeIds = async (ids) => {
  const jsonValue = JSON.stringify(ids);
  await AsyncStorage.setItem('@object-ids', jsonValue);
};
export const getIds = async (id, ids) => {
  const storedIds = await AsyncStorage.getItem('@object-ids');
  if (storedIds) {
    return JSON.parse(storedIds );
  }
};

const createId = async() => {
  const ids = await getIds();
  const id = Math.max(ids) + 1
  await storeIds([...ids,id])
  return id;
}

Edit: I added some untested unique identifier code

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda