/ jquery

Getting jQuery to work with React

The Concept

Get jQuery into bundled JS, and expose $ to global.
You will run jQuery scripts wrapped in $(function() { .. }) anyway.

The Steps

  1. Install jQuery
    npm i jQuery

  2. Import into App.js (assuming you're using create-reat-app).
    import $ from 'jquery';

  3. Load $ into global in componentDidMount.

  componentDidMount() {
    window.$ = $;
    this.grecaptcha = window.grecaptcha;

This example here shows how to expose objects to global, as well as getting global objects into react components.

Getting jQuery to work with React
Share this