Preact: Is Preact capable of replacing React?

Created on 3 Nov 2016  路  5Comments  路  Source: preactjs/preact

Sorry for stupid question, guys. Looks like Preact is really awesome, and I'm just starting to dig it.

Please tell me, wether it's possible to use all other react-components in npm within preact?
What are the possible caveats?

Thanks!

discussion documentation

Most helpful comment

What are the possible caveats?

Good question, many people have asked:

  1. Unlike React, it does not normalize events across browsers. In other words, the argument passed to event handler props (eg. onClick) is the "raw" DOM event from the browser. This is less of an issue than it was in the past due to improved browser compatibility in this area, but something to be aware of.
  2. If you want to use it as a drop-in replacement for React for an existing component which uses React APIs (mainly deprecated/legacy APIs) that are not available in Preact, you may need preact-compat
  3. It doesn't have anywhere near the volume of developer warnings that React has. If you do something wrong in a lifecycle method, React will probably complain, Preact probably won't.
  4. React has more users and much more extensive usage on large websites, combined with a larger test suite - so there is less likelihood that you'll run into edge cases with DOM APIs affecting only certain browsers or certain elements/attributes. For an example of the sort of issue I'm referring to, see https://github.com/developit/preact/issues/378 . On the other hand, the Preact codebase is very small so there is less surface area for defects.

Another way of looking at (1) and (4) is that Preact is "closer to the metal" of the web platform and the browser that you happen to be running on.

All 5 comments

it's not stupid question. have you looked preact-compat? https://github.com/developit/preact-compat

What are the possible caveats?

Good question, many people have asked:

  1. Unlike React, it does not normalize events across browsers. In other words, the argument passed to event handler props (eg. onClick) is the "raw" DOM event from the browser. This is less of an issue than it was in the past due to improved browser compatibility in this area, but something to be aware of.
  2. If you want to use it as a drop-in replacement for React for an existing component which uses React APIs (mainly deprecated/legacy APIs) that are not available in Preact, you may need preact-compat
  3. It doesn't have anywhere near the volume of developer warnings that React has. If you do something wrong in a lifecycle method, React will probably complain, Preact probably won't.
  4. React has more users and much more extensive usage on large websites, combined with a larger test suite - so there is less likelihood that you'll run into edge cases with DOM APIs affecting only certain browsers or certain elements/attributes. For an example of the sort of issue I'm referring to, see https://github.com/developit/preact/issues/378 . On the other hand, the Preact codebase is very small so there is less surface area for defects.

Another way of looking at (1) and (4) is that Preact is "closer to the metal" of the web platform and the browser that you happen to be running on.

That is a better list than I could have ever put together @robertknight 馃檱

Thank you for the robust explanation, guys! Will take a closer look on preact 馃憤
@developit @robertknight @mehmetkose

I'm going to close this out since the information here is about to get included on a new homepage for preactjs.com 馃拑

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriaanwm picture adriaanwm  路  3Comments

nopantsmonkey picture nopantsmonkey  路  3Comments

kay-is picture kay-is  路  3Comments

matuscongrady picture matuscongrady  路  3Comments

k15a picture k15a  路  3Comments