WIP: Fix setState calls
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
setStaterelated methods (usingkeyof Somethinginstead ofstring) - increases type safety and prevents typos. - Using functional logic in react
setStateclosures which is preferred in general (I would suggesting updatingtypescriptso thatsetStatecallbacks can benefit of optional chaining i.e.prevState?.sections.map(a => ...)instead ofprevState.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.