Skip to content

Instantly share code, notes, and snippets.

@developit
Last active September 22, 2022 15:44
Show Gist options
  • Save developit/abaf82fb8ba6ac2356d1b061449061e8 to your computer and use it in GitHub Desktop.
Save developit/abaf82fb8ba6ac2356d1b061449061e8 to your computer and use it in GitHub Desktop.
a lot of libs can roll with this tiny shim.

Usage:

In your webpack config:

resolve: {
  alias: {
    'react': 'preact-compat-lite',
    'react-dom': 'preact-compat-lite'
  }
}
import { * as preact } from 'preact';
export * from 'preact';
import { * as hooks } from 'preact';
export * from 'preact/hooks';
const toArray = preact.toChildArray;
const map = (c, f) => c && toArray(toArray(c).map(f));
export const Children = preact.Children = {
map: map,
forEach: map,
toArray: toArray,
only: c => toArray(c)[0],
count: c => c && toArray(c).length || 0
};
export default Object.assign(preact, hooks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment