Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@natsumi_m31

create-react-appで構築したReactアプリケーションでjQueryを使う

More than 3 years have passed since last update.

Facebook公式のcreate-react-appコマンドを使ってReact.jsアプリを爆速で作成するを読んでさっそく試してみた。
本当に記事の通りすんなり構築できたので、jQueryも読み込んでみた。

プロジェクトのディレクトリで

npm i jquery --save

んで、index.jsに追記。

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import $ from 'jquery';

$('#root').on('click',function(){
    console.log('クリックしたよ');
})  

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

あっさり動いた。
$(function () {})っていうのはいらない。

6
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?