score:0
my thought is calling new car() just call the constructor and not the render method, which means the component does not start mounting (see lifecycle document https://facebook.github.io/react/docs/component-specs.html). so the warning means "hey, your component did not start mounting, how come you want to setstate, it has something wrong".
if you are ok with using testutils, you can have something like
var car = testutils.renderintodocument(
<car />
);
score:0
first of all problem looks like to be more specific to your component, so without posting at least your render method not much can be said.
otherwise a quick fix would be to check whether your component is mounted or not, like this:
componentwillunmount() {
this.isunmounted = true;
}
setcolor(color) {
if (!this.isunmounted) {
this.setstate({ color : color });
}
}
other solution can be to use try catch:
setcolor(color) {
try {
this.setstate({ color : color });
return true;
} catch (e) {
return false;
}
}
Source: stackoverflow.com
Related Query
- How to create Chai/Mocha unit tests for a ES6 class React component?
- react create app, typescript unit test with mocha and chai what is the correct setup to support es6 modules?
- How do I create a class decorator for mixing new methods into a React component when using Typescript?
- How do I create an array of objects in a React class component through a for loop to be mapped in a functional component?
- Why do I have to .bind(this) for methods defined in React component class, but not in regular ES6 class
- how to create common helper class in React JS using ES6 which is used by another component?
- How to write an ES6 class React Component that extends a functional component?
- How can I write a unit test for a react component that calls reduxjs's mapStateToProps?
- How to wait for complete render of React component in Mocha using Enzyme?
- how can I create a react component for paypal in-context express checkout?
- How to create a React component for a bootstrap alert?
- VSCode How do I debug with es6 mocha unit tests and jsx files
- how to use Context for class Component in other module in React js
- React js unit tests for connected components - mocha
- How to create seperate component just for routes using react router?
- How to use react-alert with React component that is defined as ES6 class
- TypeScript errors in React Class Component property does not exist on type 'Readonly<{}>', not sure how to set types for state
- How can I mock a service within a React component to isolate unit tests in jest?
- How to create a loader page for a react component that is fetching data from an api
- How to create algolia autocomplete custom renderer using react class component
- How can I create multiple instances of a React component (having an infinite animation) with different values for the :root variables
- How to test the style inside the CSS class for React component using Jest and Enzyme?
- How to create a React Loop inside a component for LI items containing a picture and URL?
- How can I create a parent component for specific pages (to be able to add react context inside parent)?
- How to create a specified callback function for a setState in React Functional Component
- How to pass parameter into React component defined using ES6 class
- How to get rid of underline for Link component of React Router?
- How to create unique keys for React elements?
- How to test style for a React component attribute with Enzyme
- Figuring out how to mock the window size changing for a react component test
More Query from same tag
- Returning array react-redux
- Can't get data from firebase in react chart
- How to add min to redux form field
- Divides later into text
- firebase update function, overwrite data
- how to append 2 usestates in react js
- React App, How do you map and sort titles in an Api Array in alphabetical order
- React, I have just started coding and I have a question
- Create redux middleware with Typescript
- Unable to type in input with Unity WebGL background div in React JS
- TypeError: tours.map is not a function. Can't perform a React state update on an unmounted component
- Checkbox status does not change in react
- bufferGeometry setFromPoints with react-three-fiber
- React.js css box-shadow not working
- getting build errors while using aws-iot-device-sdk in reactjs application
- Declare font size for html element for various breakpoints in MaterialUI
- How can I use useEffect with Suspense in React?
- Authorization with respect to React Router
- How to add styling to a React project
- Consuming React useContext in a class based component in TypeSCript
- How to use dependency injected component in React (TypeScript)
- How to connect a Higher-Order Component to a Redux store?
- How to display the params on the web (React Js)
- getStaticPaths throws "TypeError: segment.replace is not a function"
- Migrating React ES6 to TypeScript: import statements don't work
- Calendar Function Call not working invalid hook call
- Exporting data to a variable number of components in React
- how to insert data in React js
- Custom react hook with useState always resetting to its initial value
- Trouble changing React class into a function