Ad
React.js Run Client Side JS After Render Finishes
I have a React app, but I need to run some client side js once the component has finished loading. What is the best way to run js that interacts with the DOM like $('div').mixItUp()
once the render function has finished and loaded. Very new to React so sorry if this is stupidly easy.
Ad
Answer
Put your code inside the componentDidMount
method on your component. See the documentation on lifecycle methods. With ES6 syntax, this will look like
class MyComponent extends React.Component {
...
componentDidMount() {
$('div').mixItUp();
}
...
}
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad