Skip to content

WIP: Fix setState calls

Lukas Möller requested to merge fix-setState into staging

This branch consists of several changes to this.setState calls. This could allow us to use PureComponent instead of Component which could result in improved performance.

Transformations include:

  • this.setState(prevState => {return {...}}) this.setState(prevState => ({...}))
  • Better ts types for setState related methods (using keyof Something instead of string) - increases type safety and prevents typos.
  • Using functional logic in react setState closures which is preferred in general (I would suggesting updating typescript so that setState callbacks can benefit of optional chaining i.e. prevState?.sections.map(a => ...) instead of prevState.sections ? prevState.sections.map(a => ...) : undefined)
  • Removing unused parameters
  • Using shorthand object syntax ({a} instead of {a: a})

There are some cases where Map / Set is used which provide no benefit when using them as immutable objects.

Although I am somewhat confident that the transformations are equivalent in terms of the outcome I would be suggest someone else checking this. This merge request is prefixed with WIP until I am certain that the transformations are equivalent and it doesn't introduce any new bugs.

Edited by Lukas Möller

Merge request reports