Skip to content

Commit

Permalink
Enable hooks! (#14679)
Browse files Browse the repository at this point in the history
* Turned enableHooks feature flag on everywhere
* Removed useHooks feature flag from tests (now that it's on by default)
* Remove useHooks feature flag entirely
  • Loading branch information
bvaughn authored Jan 23, 2019
1 parent 5267f8d commit f970487
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
43 changes: 16 additions & 27 deletions src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import shallowEqual from 'shared/shallowEqual';
import invariant from 'shared/invariant';
import checkPropTypes from 'prop-types/checkPropTypes';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {enableHooks} from 'shared/ReactFeatureFlags';
import warning from 'shared/warning';
import is from 'shared/objectIs';

Expand Down Expand Up @@ -187,17 +186,15 @@ class ReactShallowRenderer {
this._rendering = false;
this._forcedUpdate = false;
this._updater = new Updater(this);
if (enableHooks) {
this._dispatcher = this._createDispatcher();
this._workInProgressHook = null;
this._firstWorkInProgressHook = null;
this._isReRender = false;
this._didScheduleRenderPhaseUpdate = false;
this._renderPhaseUpdates = null;
this._currentlyRenderingComponent = null;
this._numberOfReRenders = 0;
this._previousComponentIdentity = null;
}
this._dispatcher = this._createDispatcher();
this._workInProgressHook = null;
this._firstWorkInProgressHook = null;
this._isReRender = false;
this._didScheduleRenderPhaseUpdate = false;
this._renderPhaseUpdates = null;
this._currentlyRenderingComponent = null;
this._numberOfReRenders = 0;
this._previousComponentIdentity = null;
}

_context: null | Object;
Expand Down Expand Up @@ -560,27 +557,19 @@ class ReactShallowRenderer {

this._mountClassComponent(element, this._context);
} else {
if (enableHooks) {
const prevDispatcher = ReactCurrentDispatcher.current;
ReactCurrentDispatcher.current = this._dispatcher;
this._prepareToUseHooks(element.type);
try {
this._rendered = element.type.call(
undefined,
element.props,
this._context,
);
} finally {
ReactCurrentDispatcher.current = prevDispatcher;
}
this._finishHooks(element, context);
} else {
const prevDispatcher = ReactCurrentDispatcher.current;
ReactCurrentDispatcher.current = this._dispatcher;
this._prepareToUseHooks(element.type);
try {
this._rendered = element.type.call(
undefined,
element.props,
this._context,
);
} finally {
ReactCurrentDispatcher.current = prevDispatcher;
}
this._finishHooks(element, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ let React;
describe('ReactShallowRenderer with hooks', () => {
beforeEach(() => {
jest.resetModules();
let ReactFeatureFlags = require('shared/ReactFeatureFlags');
// TODO: Switch this test to non-internal once the flag is on by default.
ReactFeatureFlags.enableHooks = true;
createRenderer = require('react-test-renderer/shallow').createRenderer;
React = require('react');
});
Expand Down

0 comments on commit f970487

Please sign in to comment.