I created an app with react-create-app command and i use the react 16. i want to use katrik-v fileinput (a jquery plugin) too. that is my code:
import React, { Component } from 'react';
import { Grid, Cell } from 'react-foundation';
import Header from './Heaader';
import $, { jQuery } from 'jquery';
class New extends Component {
componentDidMount(){
$(document).find('#root').find('#test-upload').fileinput();
}
render(){
return (
<div>
<Grid type="x">
<Cell medium={2} large={2} >
<label htmlFor="image" className="text-right middle">
<p className="form-label">Images</p></label>
</Cell>
<Cell medium={8} large={8}>
<div className="file-loading">
<input id="test-upload" ref='fff' type="file"
multiple />
</div>
</Cell>
</Grid>
</div>)
}
}
export default New;
When I call it in the index.js:
ReactDOM.render(<App />, document.getElementById('root'));
I'm facing this error:
TypeError: __WEBPACK_IMPORTED_MODULE_4_jquery___default(...)(...).find(...).find(...).fileinput is not a function.
$(document).find('#root').find('#test-upload').fileinput()
what is the problem?
In general, how can these two be merged?(a jquery plugin and react app)
public/index.htmlusing standard<script>tags. Then replace the line that imports jQuery with/* global $ */.import $, { jQuery } from 'jquery';with/* global $ */$object from your<script>inside your React code. Did it work?