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

130
Views
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
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!