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

67
Vistas
Set colours of React Native App through API response

It's basically Web and Mobile app. The user will be able to customise the theme on the web. When he logs in to the mobile, he will get the colour scheme along with the response object (of login API) Since I cannot call the login API again, so I am storing the colours in AsyncStorage. In my application, I have a file which I use to set colours of the whole app. Here is the code:

import AsyncStorage from '@react-native-async-storage/async-storage';
let themeColorDark = "#123A43";
let themeColorLight = "#76AEB5";
let themeActiveColor = "#206775";

const getColors = async () => {
    themeActiveColor = await AsyncStorage.getItem('primary');
    themeColorDark = await AsyncStorage.getItem('dark');
    themeColorLight = await AsyncStorage.getItem('light');
    console.log(themeActiveColor, themeColorDark, themeColorLight);
    // the results of the console: #610f0f #e2b1b1 #e7d5d5
    // while the actual colors: #206775 #123A43 #76AEB5
}
getColors();

export default {
    themeColorDark: themeColorDark,
    themeColorLight: themeColorLight,
    themeActiveColor: themeActiveColor,
};

The problem is, the result of the console is correct. But actual colours are which I initialised. I am new to React Native, so any help or alternative solution would be highly appreciated.

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

0

I think you had saved some value colour code in your AsyncStorage before. you must update your values first in AsyncStorage. use useState to keep tracking of updating data and set new values in your AsyncStorage and you're good to go

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