score:1
Accepted answer
the main problem is that you're using an id, which is inflexible and makes assumptions about the rest of the components (because ids must be globally unique).
module.exports = react.createclass({
componentdidmount: function() {
// pass a dom node to the constructor instead of it using an id
this.component = new component(this.getdomnode());
this.component.start();
},
componentwillunmount: function() {
this.component.destroy();
},
render: function() {
return <div />;
}
});
your componentwillunmount was fine, but the one place you set this.component will always run before componentwillunmount, and there's no other reason it'd be assigned/deleted, so the if statement isn't needed.
also the arguments both weren't used, and aren't provided to componentwillunmount. that signature belongs to componentdidupdate.
Source: stackoverflow.com
Related Query
- Pattern for syncronously loading a react Provider component
- React component loading pattern (or anti-pattern?)
- Set loading state before and after an action in a React class component
- gapi is not defined when loading React Component
- React countup animation starts immediately after the page loading , should start when scrolled to the component (without jquery)
- Best way to show a loading spinner/gif while my React component is fetching via AJAX?
- React anti pattern, defined a component inside the definition of another component
- What is the correct pattern in React JS to invoke a component method on specific props change?
- Lazy loading in react - the component is not loading
- Loading JSON file into React Component state | Wepback2
- Trouble Loading Method in React Component
- React Native - Displaying a Loading Screen Component in a Javascript Promise
- Async loading script within react component
- Custom React Component Library not loading CSS when installed as dependency in another react project
- loading external css file just for one react component
- External js is loading in react component only after refresh
- Strategy pattern with React component
- How to make a lazy loading high order component in React
- How to set a loading state for react component while sorting and filtering data?
- Loading spinner not showing in React Component
- Webpack & React getComponent() not loading component (async)
- Execute script after loading server side rendered React component
- Loading react component from url
- React update component after loading data
- React - prop is undefined when loading the same component
- Loading Google script in React Component
- React loading HOC: all the props provided in a list are set to optional and if any of them is undefined shows a spinner instead of the component
- Loading Django static files from React component
- Loading React Sidebar in Parent Component when Child Component Loads
- Loading the component on react js
More Query from same tag
- How to count the number of objects in .json
- React router v6 routes with Fallback
- How to send file metadata over api using fetch
- React single page application
- how to update html content dynamicaly with for loop in react js javascript
- how to debug code with console.log when the code runs slow
- Create props object inline
- How can I create an effective private route using the latest version of react-router-dom
- React router always renders first route in nested component
- React this doesn't work sometimes in the callback of setState
- Trying to create a select element using database values in a react-redux app
- Nesting routes along with redux integration not working?
- Receiving 404s in my React app despite setting historyApiFallback to true for webpack-dev-server
- React-Testing: Debug, why this jest snapshot test is failing for a component using Material UI's Grid
- How to use the same port for React Js and Node Js?
- Module '"@ionic/core"' has no exported member 'setupIonicReact' while upgrading ionic 5 to 6
- Display element on increase of counter in ReactJS
- How to properly use Modal in Fluent UI
- Is it possible to create a React component interface?
- Implement "as" prop in React component in TypeScript
- POST request with Axios not sending data to my server
- Structuring Normalized JSON response in Redux store and mapping to React component props
- "Function components cannot be given refs" with forwardRef and connect in function component
- sendPasswordResetEmail failed: First argument "email" must be a valid string
- React DnD drag item is not updating with useState
- React state gets updated only after I submit the form twice
- I get TypeError: Cannot read property 'then' of undefined when I try to test async action
- 'sh' is not recognized as an internal or external command
- ReactJS: Get multiple checkboxes value with material-ui
- Deleting object of a state array in React using id