How to ensure jQuery at the global level in a React component?

1k Views Asked by At

I am using froala editor in my React application which requires jQuery to be available at a global level. Now I know I can add below to my webpack file to ensure same:

plugins: [
new webpack.ProvidePlugin({
  $: "jquery",
  jQuery: "jquery"
 })
]

but I don't want this to be part of my webpack config, is there a way I can pass same mapping (defined above) to my React component that is rendering froala editor?

I came across options like:

 window.$ = window.jQuery = require("jquery");

mentioned here https://github.com/webpack/webpack/issues/2180#issuecomment-196048732

but I am unable to figure out how can declare this in froala editor component as window is accessible only after component has mounted.

0

There are 0 best solutions below