souporserious/react-measure

warn about infinite loops

Opened this issue · 2 comments

Just ran into this. Should have some documentation noting that infinite loops are easy if you aren't paying attention to measure + setState.

Here's a simple example to prevent infinite looping

handleInputResize = ({ bounds }) => {
  if (this.state.inputWidth !== bounds.width) {
    this.setState({ inputWidth: bounds.width })
  }
}

Maybe there's a better way to prevent this or even warn when onResize updates too much? I'm open to ideas.

This can also happen even without setState. E.g. when the content changes depending on the sizes and the change in the content in turn affects the sizes. I think it would make sense to warn about this in the README.

Also ran into this! At least it wasn't a big in itself :)