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

116
Visualizações
Detect React with JavaScript

As a library author, I'd like to know whether my library is being used with React or with some other UI framework (Vue, Svelte, ...).

Is there a way to detect whether React's code was loaded?

The following Stack Overflow answers don't answer this question because they only work using the developer console. (Whereas I want to detect React from the perspective of a JavaScript library.)

  • How to tell if a web application is using ReactJs
  • How can I detect if a website is built with React?

Context: I'm building vite-plugin-ssr. (It's like Next.js/Nuxt but as a do-one-thing-do-it-well Vite plugin.)

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I've come up with the following solution:

const isReactApp = !!Array.from(document.body.querySelectorAll("*")).find((node) => node._reactRootContainer)

It works on create-react-app as well as gatsby projects (possible more as I've tested only those so far).

Basically it traverses through all elements and check if the magic reactRootContainer attribute is defined on the element. Consider that the snippet could be very slow on huge pages with lots of DOM nodes.

However, I would generally advise against using this approach as it's likely that the reactRootContainer property will change (since it's private) in the near future.

A better approach would be to let the developers who'll use your library tell your library that they are using react (or vue or svelte or x).

Something like:

import MyLibrary from '@mylibrary/react';
about 4 years ago · Santiago Trujillo Relatório
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