mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
IsMounted should always return a boolean.
Fixes #3814. isMounted used to return undefined if internalInstance was undefined after component was unmounted.
This commit is contained in:
1 parent
5509cd74a4
commit
5ef0b416df
2 files changed
+22
-4
No files matched your search
@@ -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