-
Thinking a little bit about my work presentation for the new year [[permanent-notes/making-eco-friendly-websites]].
-
The Preact compat layer lets you swap out React layer for Preact for existing React codebases. My understanding so far is that it provides the exact same API without any compromises. We did this for Penso and there was not issues and we’re using the usual react features such as context, various hooks like
useState
,useEffect
third party libs like styled components. -
Worth noting that the
preact-compat
layer is an additional 2kb overhead. But preact is so small already at 3kb that 5kb in total is not so bad compared to reacts ~120kb -
I like this summary why less code is better from https://robertknight.me.uk/posts/preact-react-tradeoffs/
Having less code makes everything which processes that code
run or start faster. For developers this includes build times, test
execution times, continuous integration cycle times and how long
it takes the application to load in development. Fast cycle times
make for happier and more productive developers. For end users,
it affects how long it takes the application to load in their browser,
particularly on lower-end devices and slower networks. -
-
I cant find any tradeoffs with using preact over react which does make me question why we dont just use preact for everything?!
- A big one is that it will always be slower to get new react features, such react server component.
-
the
preact-compat
layer provides 100% api compatibility with react.