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

192
Visualizações
How to properly import a javascript file/function API to a React.js app?

Hey Stackoverflow :) Long time reader, first time poster. To the point:

I'm fairly new to web programming (done much more C# and game programming). I've been given a task that requires me to write a simple React.js app. I am to use an included api.min.js javascript file that includes an "API", that is supposed to sort of mimic a server, has a set of built in functions to fetch data ('/getitem', '/getusers', '/putitem', etc), and mimics lost requests now and then. The API code has been minified and is one single line of some 4500 characters, and sadly i don't think i can include all the code from this file, since it's not mine (and, well it's 4500 chars :P). But some clues: when beautified it starts off like this:

var api = function() {
  function t(t) {
    for (var e = t.length - 1; e > 0; e--) {
      var n = Math.floor(Math.random() * (e + 1)),
        r = t[e];
      t[e] = t[n], t[n] = r
    }
    return t
    etc...

And ends like this:

              etc...
              },
              setRequestHeaders: function(t, e) {
                if ("number" != typeof t && "string" != typeof t && "number" != typeof e && "string" != typeof e) throw new Error("Arguments both header and value must be numbers or strings");
                l[t] = e
              }
            };
          return m
        };
      return {
        XMLHttpRequest: y
      }
    }();

One of the examples included in the file looks like this:

// Example 1:
var x = api.XMLHttpRequest();
x.onreadystatechange = function() {
  console.log(x.readyState, x.status, x.responseText);
};
x.open("GET", "/getusers");
x.send();

If i paste the API line and the example code into say, jsfiddle.net, it works fine and gives me the data in a format i would know how to use. But i can't seem to get it to work in my React-project in VScode. Whenever i try to import the file, i get errors of the type

Line 6:7:     Expected an assignment or function call and instead saw an expression  no-unused-expressions

That would be the line:

t[e] = t[n], t[n] = r

... from the first code example above.

So I'm a bit clueless as to how to proceed atm... Does anyone have any suggestions on how i could include this API in my VScode React.js project and access the functions from the api.min.js file? I feel like there probably is some really simple solution to this, but as i said, i am fairly new to web programming and i still lack some of the fundamentals i think. I've looked around here, google, youtube etc but i can't seem to find what I'm looking for. Might be because i don't really know what i'm looking for :)

If anyone could help i would be ever grateful!

Thanks

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