Wednesday, 9 November 2022

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.)

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

EDIT: I need to be able to detect React as soon as React is loaded in the browser, before React even renders/hydrates the page. So far, all answers below are detecting React too late.



from Detect React with JavaScript

No comments:

Post a Comment