I got stuck with below error and unable to fix it. In my react app I have installed jquery as a library and imported it in root component so I haven't included cdn in my index.html.
Uncaught ReferenceError: $ is not defined at home:13 (anonymous) @ home:13
I found following many solutions but all of them are talking about including jquery cdn in index.html but none of them talking about resolving the issue when we import jquery as lib in react component.
My index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Netext</title>
<link rel="icon" href="/images/logo123.ico" type="image/x-icon"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Import Bootstrap CSS from CDN for easy replacement/removal -->
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Import bundled/compiled CSS -->
<link rel="stylesheet" type="text/css" href="/app.css">
<link rel="stylesheet" type="text/css" href="/circle.css">
<link rel="stylesheet" type="text/css" href="/custom.css">
<link rel="stylesheet" type="text/css" href="/cropper.css">
<style>
html, body {
min-height: 100%;
margin:0;
padding:0;
background: #e6ecf0 none;
}
#app{
min-width: 300px; /* 100px x3 = 300 */
min-height:100%;
}
</style>
</head>
<body>
<div id="app" class="wrapper">
</div>
</body>
<!-- Import bundled JavaScript -->
<script src="/bundle.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(window).on('scroll', function () {
if ($(window).scrollTop() >= 20) {
$('.navbar').addClass('compressed');
} else {
$('.navbar').removeClass('compressed');
}
});
});
</script>
</html>
App.js
import React, { Component } from 'react';
import HeaderTemplate from './Layout/Components/Header';
import FooterTemplate from './Layout/Components/Footer';
import imports from './common/imports';
import config from './config';
import RefreshIndicator from 'material-ui/RefreshIndicator';
import 'bootstrap/dist/css/bootstrap.min.css'
// import 'bootstrap/dist/css/bootstrap-theme.min.css' // optional
import 'jquery/dist/jquery.min.js' // I have imported jquery here
import 'bootstrap/dist/js/bootstrap.min.js'
class App extends Component {
constructor(props){
super(props);
this.state = {
showLoading: true
}
}
render() {
return (
<div>
<HeaderTemplate logo="Postme" />
<div id="demo-settings" className="">
<a href="#" id="demo-settings-toggler" className="fa fa-dot-circle-o"></a>
</div>
<div className="container-fluid bodyfluid">
{this.props.children}
</div>
<FooterTemplate />
</div>
);
}
}
export default App;
PS:- I am importing jquery as library but not including as script in index.html