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

243
Visualizações
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 à 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