Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda