Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.19 throws setState(...): You passed an undefined or null state object; instead, use forceUpdate() #1119

Closed
hyperknot opened this issue May 24, 2018 · 8 comments · Fixed by #1129

Comments

@hyperknot
Copy link

Upgrading to 9.19 started throwing a React warning with React 15.6:

Warning: setState(...): You passed an undefined or null state object; instead, use forceUpdate()

I'm using it like this:

import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer'
import List from 'react-virtualized/dist/commonjs/List'

@observer
export class FeatureList extends React.Component {
  rowRenderer({ key, index, style }) {
    return <FeatureListItem key={key} style={style} feature={featureStore.featureArray[index]} />
  }

  render() {
    if (!mapUIStore.ready) return null

    return (
      <ul id="panel-items-list">
        <AutoSizer>
          {({ height, width }) => (
            <Observer>
              {() => (
                <List
                  width={width}
                  height={height}
                  rowCount={featureStore.count}
                  rowHeight={31}
                  rowRenderer={this.rowRenderer}
                  scrollToIndex={mapUIStore.scrollToIndex}
                />
              )}
            </Observer>
          )}
        </AutoSizer>
      </ul>
    )
  }
}

The warning happens when scrollToIndex is updated.

@wuweiweiwu
Copy link
Collaborator

Can you provide a codesandbox with a repro?

And perhaps a more detailed error message?

@hyperknot
Copy link
Author

OK, I'll have a look at making one.

@wuweiweiwu
Copy link
Collaborator

react 16 allows return null from setState to avoid a re-render.

https://teamtreehouse.com/library/returning-null-from-setstate.

I would suggest upgrading react. but it's also just a warning in dev.

I'll look into refactoring some setState calls to avoid setting null

Hope that helps!

@hyperknot
Copy link
Author

hyperknot commented May 24, 2018

I've especially downgraded to React 15.6 until the Chrome translate bug is fixed in React 16.

But I don't understand this already seems to be a breaking change, then why is it just a minor release?

@wuweiweiwu
Copy link
Collaborator

Its because there was no changes that weren't backwards compatible following semvar and the rewrite to 16.x lifecycle functions had no api changes.

@wuweiweiwu
Copy link
Collaborator

@TrySound Should this be a breaking changes?

@TrySound
Copy link
Collaborator

Yep this is a breaking change. Try to fix it. We will return null in v10.

@wuweiweiwu
Copy link
Collaborator

Gotcha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants