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

242
Views
How can I deserialize a nested React Element which is an elemen of a nested object inside an array?

Hey guys I have a tough one here

I need to store and retrieve an object with nested elements and a function which returns serialized in the clients localStorage. As for the storing and retrieving, it works. But I am having an issue with functions which have been stringyfied, but won't go back to be actual functions anymore.

Here is an example of an array element:

enter image description here

As far as I am aware, this is called serialized in the JSON-Jargon. And the goal would be to unserialize them again in order to make them function again. In order to be able to store functions in the JSON format, I had "replace and revive" the arrays which had to be stored.

  let replacer = (key, value) => {
if (typeof value === "function") {
  return value.toString();
}
return value;

I turn functions to string and return them to the JSON. I invoke this helper function like this:

 localStorage.setItem(
                  "currentConfiguration",
                  JSON.stringify(
                    tableRef.current.dataManager.columns,
                    replacer,
                    2
                  )

Here is the code which is actually supposed to do: Undo what the replacer did and return actual functions instead of their strings.

let reviver = (key, value) => {
    if (typeof value === "string" && value.indexOf("function ") === 0) {
      let functionTemplate = `(${value})`;
      return eval((functionTemplate));
    }
    return value;
  };

Currently I am facing this screen whenever I try to render: enter image description here

Would appriciate if anyone could lend a helping hand

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!