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

197
Views
tratando de almacenar respuestas api en almacenamiento asincrónico pero no puedo almacenarlo

aquí he pegado un código que es un componente de clase escrito para la gestión del estado de mobx y lo estoy llamando a otro archivo, el problema es que tengo más de 450 respuestas api y necesito almacenarlo localmente, así que lo probé pero no obtengo ningún valor ni los datos almacenados en la base de datos por favor ayúdenme gracias de antemano ..

 class ProductStore { constructor() { makeAutoObservable(this); } screenWidth = width; screenHeight = height; headerHeight = 0; isiOS = Platform.OS === 'ios'; isAndroid = Platform.OS === 'android'; isProductLoading = 'pending'; productData = []; filterdData = []; search = ''; isFlatlistRender = false; setFields(eName, data) { this[eName] = data; console.log(eName, data); } getproductData = () => { if (this.isProductLoading == 'loading') { return true; } this.isProductLoading = 'loading'; this.productData = []; let headers = new Headers(); headers.set( 'Authorization', 'Basic ' + encode('username:password'), ); fetch('some_url', { method: 'GET', headers: headers, }) .then(response => response.json()) .then(responseJson => { console.log('.....', responseJson); AsyncStorage.setItem( 'ACCESS_TOKEN', JSON.stringify(responseJson), err => { if (err) { console.log('an error'); throw err; } console.log('success'); }, ).catch(err => { console.log('error is: ' + err); }); try { const value = AsyncStorage.getItem('ACCESS_TOKEN'); if (value !== null) { console.log(JSON.parse(value)); } } catch (error) {} this.productData = responseJson; this.isProductLoading = 'done'; }) .catch(error => { console.error(error); this.isProductLoading = 'error'; }); }; } export default new ProductStore();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

AsyncStorage.getItem() devuelve una promesa, no el valor. Entonces, simplemente agregue un bloque then después de la línea AsyncStorage.getItem('ACCESS_TOKEN'); . seria asi

 AsyncStorage.getItem('ACCESS_TOKEN').then(value => { if (value !== null) { console.log(JSON.parse(value)); } }).catch(err => console.error(err));
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!