Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Cómo usar useAsyncStorage para establecer el estado de una matriz

Tengo este código de los documentos de almacenamiento asíncrono . Sin embargo, esto solo funciona para establecer el estado de los valores de cadena. ¿Cómo puedo hacer con una matriz de objetos?

 export default function App() { const [value, setValue] = useState('value'); const { getItem, setItem } = useAsyncStorage('@storage_key'); const readItemFromStorage = async () => { const item = await getItem(); setValue(item); }; const writeItemToStorage = async newValue => { await setItem(newValue); setValue(newValue); }; useEffect(() => { readItemFromStorage(); }, []); return ( <View style={{ margin: 40 }}> <Text>Current value: {value}</Text> <TouchableOpacity onPress={() => writeItemToStorage( Math.random() .toString(36) .substr(2, 5) ) } > <Text>Update value</Text> </TouchableOpacity> </View> ); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Los documentos de uso mencionan que solo se pueden almacenar datos de string .

Consulte https://react-native-async-storage.github.io/async-storage/docs/usage

Para almacenar un Object o Array , deberá serializarlo con JSON.stringify(myObj) antes de escribirlo en el almacenamiento y deserializarlo con JSON.parse(myObj) inmediatamente después de leerlo desde el almacenamiento.

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar JSON.parse(retrievedItemFromStorage) para analizarlo en un Array/Object

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!