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

244
Vistas
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
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