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

132
Vistas
Getting values from localstorage and resolving Promise

I do have some noobie question. I need to get a value from localstorage, but I am using some specifc methods that we have in our app. I am setting my value with:

public setValue = async (key: keyof StorageContent, val: any) => {
    if (!localStorage) {
      console.warn("StorageManager: localStorage is not defined");
      return;
    }
    // Let's convert `undefined` values to `null` to get the value consistent
    if (val === undefined) {
      val = null;
    } else {
      val = JSON.stringify(val);
    }

    return localStorage.setItem(key, val);
  };

After this is done I am using

 static getBackendVersion() {
    return StorageManager.getValue("backendVersion");
  }

getValue

public getValue = async (key: keyof StorageContent) => {
    if (!localStorage) {
      console.warn("StorageManager: localStorage is not defined");
      return undefined;
    }

    const item = localStorage ? localStorage.getItem(key) : null;
    if (!item || item === "null") {
      return undefined;
    }
    try {
      return JSON.parse(item);
    } catch (e) {
      return undefined;
    }
  };

In my react component where I am using state and component id mount to get this done

 state: Readonly<IMainScreenState> = {
    screenKey: RouteHelper.getScreenRouteKey(this.props.match),
    apiVersion: "",
  };

  public componentDidMount() {
    const backendVer = StorageHelper.getBackendVersion();
    this.setState({ apiVersion: backendVer });
  }

After this i want to render this

 <aside className="Version">
    <span>F:{AppConfig.PlatformVersion} / </span>
    <span> B:{apiVersion}</span>
 </aside>

But this is getting me error Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. In conolse log i have

console.log

i know that i can get this with localStorage.getItem() but we need to use this helpers to get this done clean

about 4 years ago · Juan Pablo Isaza
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