Skip to content

Commit

Permalink
No setState(null) (#1129)
Browse files Browse the repository at this point in the history
* react 15 throws warning if setState `null`

* removing extra return null
  • Loading branch information
wuweiweiwu committed Jun 1, 2018
1 parent 5878125 commit fb68696
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class Grid extends React.PureComponent<Props, State> {
: SCROLL_DIRECTION_BACKWARD
: this.state.scrollDirectionVertical;

const newState: Object = {
const newState: $Shape<State> = {
isScrolling: true,
scrollDirectionHorizontal,
scrollDirectionVertical,
Expand Down Expand Up @@ -597,29 +597,26 @@ class Grid extends React.PureComponent<Props, State> {
// In that event we need to remeasure.
if (!instanceProps.scrollbarSizeMeasured) {
this.setState(prevState => {
prevState.instanceProps.scrollbarSize = getScrollbarSize();
prevState.instanceProps.scrollbarSizeMeasured = true;
prevState.needToResetStyleCache = false;
return prevState;
const stateUpdate = {...prevState, needToResetStyleCache: false};
stateUpdate.instanceProps.scrollbarSize = getScrollbarSize();
stateUpdate.instanceProps.scrollbarSizeMeasured = true;
return stateUpdate;
});
}

if (
(typeof scrollLeft === 'number' && scrollLeft >= 0) ||
(typeof scrollTop === 'number' && scrollTop >= 0)
) {
this.setState(prevState => {
const stateUpdate = Grid._getScrollToPositionStateUpdate({
prevState,
scrollLeft,
scrollTop,
});
if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
return stateUpdate;
}
return null;
const stateUpdate = Grid._getScrollToPositionStateUpdate({
prevState: this.state,
scrollLeft,
scrollTop,
});
if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
this.setState(stateUpdate);
}
}

// refs don't work in `react-test-renderer`
Expand Down Expand Up @@ -1436,19 +1433,16 @@ class Grid extends React.PureComponent<Props, State> {
* Useful for animating position changes.
*/
scrollToPosition({scrollLeft, scrollTop}: ScrollPosition) {
this.setState(prevState => {
const stateUpdate = Grid._getScrollToPositionStateUpdate({
prevState,
scrollLeft,
scrollTop,
});

if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
return stateUpdate;
}
return null;
const stateUpdate = Grid._getScrollToPositionStateUpdate({
prevState: this.state,
scrollLeft,
scrollTop,
});

if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
this.setState(stateUpdate);
}
}

static _wrapSizeGetter(value: CellSize): CellSizeGetter {
Expand Down Expand Up @@ -1530,8 +1524,8 @@ class Grid extends React.PureComponent<Props, State> {
);
if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
this.setState(stateUpdate);
}
this.setState(stateUpdate);
}

static _getCalculatedScrollTop(nextProps: Props, prevState: State) {
Expand Down Expand Up @@ -1626,8 +1620,8 @@ class Grid extends React.PureComponent<Props, State> {
);
if (stateUpdate) {
stateUpdate.needToResetStyleCache = false;
this.setState(stateUpdate);
}
this.setState(stateUpdate);
}

_onScroll = (event: Event) => {
Expand Down

0 comments on commit fb68696

Please sign in to comment.