1

I'm trying to add the jquery module select2 to my react project which has been created by create-react-app.

I'm running

npm install --save select2

and can see that the dependency is correctly added to my package.json.

Then I add this to a global javascript-file outside my react-code:

$(function () {
    $('select').select2();
}); 

This does not work as the select2 script is not included.

What am I doing wrong? Should I somehow run the jquery code inside my react code? Should I do something specific to include the select2 library?

This might be a very basic problem, but I'm confused how scripts are actually included when running under the framework of create-react-app.

1 Answer 1

2

After som more research I realize that I can do the following:

  1. Run 'npm install --save jquery'. This will add jquery to package.json

  2. Add this import statement to my component: 'import $ from 'jquery';'

Any comments or more correct solutions will still be appreciated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.