DEV Community

Cover image for Is Preact worth checking in 2021?
Marcin
Marcin

Posted on • Updated on • Originally published at marcin.codes

Is Preact worth checking in 2021?

Preact is a framework that aims to be fast with a smaller size alternative React with the same API. Comparing to such a giant as React isn’t easy. Let’s see if Preact should be ashamed of that comparison!


Features

Most of Preact features are the same as in React. Hooks, Portals, Suspense all of this are available in Preact. There are some small differences in Preact. You can read about it here https://preactjs.com/guide/v10/differences-to-react.

So why you should consider picking Preact instead of React?

Smaller size

Preact has a smaller footprint. According to bundlephobia Preact (with @preact/compat) is almost 4.5kB minified and gzipped. Comparing to React (with React DOM) which size is 42kB, Preact is 90% smaller. That’s a huge difference. Here we need to remember that Preact is fully compatible with React apps and it can be replaced in most of the apps without changing the line of code.

Preact is gaining popularity

Alt Text

The trend is visible, people are reaching out more and more often. Wider community lead library authors to support not only react but also Preact. You can see here a community-made project using Preact.

https://github.com/preactjs/awesome-preact

Preact is simpler

Look at this and see in-depth how Preact looks under the hood. This simplicity benefits!

This is code for useState:

export function useState(initialState) {
 currentHook = 1;
 return useReducer(invokeOrReturn, initialState);
}
Enter fullscreen mode Exit fullscreen mode

And this one is for useRef:

export function useRef(initialValue) {
 currentHook = 5;
 return useMemo(() => ({ current: initialValue }), []);
}
Enter fullscreen mode Exit fullscreen mode

Do you see how simple it is? Re-using other parts of well-designed code has so much impact.

Summary

Simplicity and well-designed API are powerful. The small size means less code to run this led to faster apps. I made a chrome extension called pullrequests-templates using preact. The developer experience was amazing and I’m considering starting all my new projects using Preact. Definitely recommend everyone to check it.

Answering the question in the title: Yes!

Top comments (0)