This is a quick comparison of a resulting code when using class components and function components with hooks.
The comparison shows the advantage of using hooks for the sake of not only DX but UX — less code to ship.
Testing components code can be found below. Babel was used for building and minifying the code. We compare ES5 and ES6 version (bundled for old browsers and new, using preset-env).
Class Component | Function Component | Difference | |
---|---|---|---|
min | 2229B | 927B | -58.41% |
min+gzip | 897B | 524B | -41.58% |
Class Component | Function Component | Difference | |
---|---|---|---|
min | 524B | 349B | -33.39% |
min+gzip | 295B | 230B | -22.03% |