mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #3815 from neojski/isMounted-should-return-boolean
IsMounted should always return a boolean.
This commit is contained in:
@@ -761,10 +761,11 @@ var ReactClassMixin = {
|
||||
}
|
||||
}
|
||||
var internalInstance = ReactInstanceMap.get(this);
|
||||
return (
|
||||
internalInstance &&
|
||||
internalInstance !== ReactLifeCycle.currentlyMountingInstance
|
||||
);
|
||||
if (internalInstance) {
|
||||
return internalInstance !== ReactLifeCycle.currentlyMountingInstance;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -287,6 +287,23 @@ describe('ReactComponentLifeCycle', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('isMounted should return false when unmounted', function () {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
return <div/>;
|
||||
}
|
||||
});
|
||||
|
||||
var container = document.createElement('div');
|
||||
var instance = React.render(<Component />, container);
|
||||
|
||||
expect(instance.isMounted()).toBe(true);
|
||||
|
||||
React.unmountComponentAtNode(container);
|
||||
|
||||
expect(instance.isMounted()).toBe(false);
|
||||
});
|
||||
|
||||
it('warns if findDOMNode is used inside render', function() {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createClass({
|
||||
|
||||
Reference in New Issue
Block a user