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

203
Visualizações
Undefined properties of a variable

I don't know if this is too specific to be asked in a Stack Overflow, but I've gone through a few year old tutorial on how to build a Codepen-like app with React (NextJS) and MongoDB.

At first I tried to just hand-pick features I actually need for what I am about to do with this app, but then I got stuck in an error message that follows:

Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'updatedRecord')

Which refers to my save function (index.js):

const save = async () => {
        setSaving(true);
        const requestOptions = {
            method: !id ? "PUT" : "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({
                html: htmlValue,
                css: cssValue,
                js: jsValue,
                id: id,
            }),
        };
        const response = await fetch(`../api/pens/${id}`, requestOptions);
        const {
            data: { updatedRecord, newRecordId },
        } = await response.json();

        setSaving(false);
        if (!updatedRecord) {
            await router.push(`?id=${newRecordId}`);
        }
    };

This error gets triggered every time I try to save a new pen (by pressing the save button, which calls the save function presented above), and from what I've been able to gather up is that there is probably something that's no longer supported by the newer versions of React/NextJs/MongoDB/NodeJs - just can't figure out what it is.

Here is the version of his (who wrote the tutorial) code in it's entirety. I've pretty much tried everything from cloning the entire project to my own and yet can't get it to work, so I'm in a bit of a pinch here.

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