• Stars
    star
    231
  • Rank 173,434 (Top 4 %)
  • Language
    JavaScript
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ES6 module exposing the latest version of react and react-dom

es-react

An ES6 module exposing the latest version of react, react-dom, react-is, and prop-types

Ever wanted to just import react into your project as a module without a build step or even script tags? Native browser support for module imports is pretty good so this should be an option for react developers now! Alas, there has not been an ES6 module compatible build released yet.

This package allows you import react and react-dom as ES6 modules from a CDN like unpkg:

<script type="module">
  import { React, ReactDOM, PropTypes } from 'https://unpkg.com/es-react';

  ReactDOM.render(
    React.createElement('h1', {}, 'Hello from es-react'),
    document.body
  );
</script>

By default es-react exports the production build of react. For the development build use the /dev subfolder:

import { React, ReactDOM } from 'https://unpkg.com/es-react/dev';

You may also import any members of the React package directly:

import React, {
  Component,
  useState /* ... */,
} from 'https://unpkg.com/es-react';

And every package is also being provided as a separate file:

  • es-react/index.js: Exports all of React and exports { React, ReactDOM, ReactIs, PropTypes }
  • es-react/react.js: Exports all of React plus a default export
  • es-react/react-dom.js: Exports all of ReactDOM plus a default export (but not react-dom/server)
  • es-react/react-is.js: Exports all of ReactIs plus a default export
  • es-react/prop-types.js: Exports all of PropTypes plus a default export
  • es-react/react-dom-server.js: Exports all of ReactDOMServerBrowser plus a default export

All development-versions of these packages are also available under es-react/dev/.

Features

  • All the latest React features (hooks, suspense, lazy, memo etc.)
  • Use React directly from any javascript file (no build step required)
  • Compatible with htm (for JSX compilation at runtime)

Usage

Import React and ReactDOM directly from any script with type="module". The package is intended to be available from unpkg (without having to append ?module to the package name).

import { React, ReactDOM } from 'https://unpkg.com/[email protected]';

It is strongly advised that you specify a version when requesting the module – this speeds up the request time and helps with caching. If you don't specify a number then unpkg will redirect and serve up the latest available version.

Example

Create a new file, copy the code below into it and then open the file in a browser – or try online.

If you would like the browser to reload when you update the code, then you can use a dev server like servor dependency free by running npx servor --reload --browse.

<script type="module">
  import { React, ReactDOM } from 'https://unpkg.com/[email protected]';

  import htm from 'https://unpkg.com/htm?module'
  const html = htm.bind(React.createElement)

  const Counter = props => {
    const [count, setCount] = React.useState(parseInt(props.count))
    return html`
      <div>
        <h1>${count}</h1>
        <button onClick=${e => setCount(count - 1)}>Decrement</button>
        <button onClick=${e => setCount(count + 1)}>Increment</button>
      </div>
    `
  }

  ReactDOM.render(
    html`
      <h1>Look Ma! No script tags, no build step</h1>
      <${Counter} count=0 />
    `,
    document.body
  )

</script>

Implementation

The latest versions of all packages are installed via (pinned) entries in package.json and built and bundled using Rollup with automatic code splitting.

The exports of each package are automatically expanded and object-assign is stripped from the output, since all browsers that support ESM will also support Object.assign (See scripts/expand-exports-plugin.js and scripts/replace-object-assign.js for the Babel plugins that do this)

Acknowledgements

Barely any of the code in this repo is written by myself. It is just a wrapper for React that is written and maintained by the team at Facebook. Thanks to my employer Formidable for allowing me the time to think about and work on fun and experimental projects like this.

More Repositories

1

react-slack-clone

Complete chat application, built with Chatkit | by @lukejacksonn
JavaScript
1,347
star
2

perflink

Low friction JavaScript benchmarks that you can share via URL
JavaScript
1,208
star
3

servor

Dependency free file server for single page app development
JavaScript
1,042
star
4

ijk

Transforms arrays into virtual dom trees; a terse alternative to JSX and h
JavaScript
467
star
5

oceanwind

Compiles tailwind shorthand into css at runtime. Succeeded by Twind.
JavaScript
264
star
6

GreedyNav

A responsive navigation menu that stacks items into a dropdown menu when they overflow
JavaScript
231
star
7

csz

Runtime CSS modules with SASS like preprocessing
JavaScript
218
star
8

monacode

An es-module wrapper around the monaco editor and prettier
JavaScript
167
star
9

create-es-react-app

A create-react-app like template using only es-modules (no build step).
JavaScript
103
star
10

hyperapp-pwa

A minimalist, progressive web app compliant template for hyperapp projects
JavaScript
72
star
11

domz

A proxy function to help build virtual DOM trees from functions
JavaScript
62
star
12

hyperapp-electron

A minimal electron app starter with hyperapp, livereload and redux devtools
JavaScript
51
star
13

Actuate

One line easy actuation of CSS animation sequences
JavaScript
41
star
14

chattery

A GitHub action that creates chatrooms for pull requests
Ruby
29
star
15

esm

A single file es module prototyping tool
JavaScript
29
star
16

blub

[POC] resolving es module dependency graphs on the server
JavaScript
27
star
17

deployable

A ready-to-deploy static web app template and tutorial
HTML
25
star
18

hyperapp-firebase-auth

🔥 Drop in authentication for hyperapps using firebase
JavaScript
19
star
19

Lorem

Generates random lorem ipsum snippets
JavaScript
19
star
20

Malette

A color picker tool for the google material design palette
JavaScript
18
star
21

cube

Rubik's Cube simulator with F2L/OLL/PLL algorithms
JavaScript
17
star
22

hyperapp-wiki

Example of how hyperapp could be used to serve its on wiki with gh-pages
HTML
13
star
23

blog

A forkable personal blog that runs on GitHub pages. Demo 👉
JavaScript
12
star
24

hyperapp-hn

First attempt at a community hacker news PWA built with HyperApp
JavaScript
10
star
25

vuid

❄️ Very unique identifiers in the browser using web cryptography (144b)
JavaScript
10
star
26

hyperapp-fetch

A component to fetch and cache data before rendering a view
JavaScript
10
star
27

tetris

The classic NES Tetris built with hyperapp
JavaScript
9
star
28

ipsums

Generate random amounts of lorem ipsum text
JavaScript
8
star
29

framer

Easily apply a frame overlay to an avatar photo
JavaScript
8
star
30

hyperapp-starter

A minimalist starter for hyperapp projects
JavaScript
6
star
31

Protohype

A set of aliases for commonly used CSS properties and values
CSS
5
star
32

hyperapp-router

A frontend router for hyperapp view switching
JavaScript
4
star
33

preroll

An opinionated web project builder with dev server
JavaScript
3
star
34

dankon

🗺 Learn to express your gratitude in 140+ different languages
JavaScript
3
star
35

streamer

🚰 Streams of reasonably interesting data published reasonably stochastically
JavaScript
2
star
36

fb-sdk

Load and queue calls to the facebook sdk
JavaScript
2
star
37

huy

useful h function ui elements
JavaScript
2
star
38

plural

picture-in-picture interface for youtube videos
JavaScript
2
star
39

hyperapp-two

A multi-page and multi-component boilerplate hyperapp project
JavaScript
2
star
40

xs

An extra small, stand alone web application template
HTML
1
star
41

youtube-eco

A chrome extension that optimizes youtube streaming quality
JavaScript
1
star
42

hyperapp-unite

A utility function for merging reducers, effects and routes with safe namespacing
JavaScript
1
star
43

Stash

A jQuery plugin that can instigate application/octet-stream downloads of local content
JavaScript
1
star
44

Browver

A JavaScript plugin that detects if a browser is too and points to the latest browser downloads..
JavaScript
1
star
45

lukejacksonn.github.io

My personal homepage to be hosted at http://lukejacksonn.com
HTML
1
star
46

gitinit

Create a new git repo based on an already existing repository
JavaScript
1
star
47

feeder

My awesome pusher feeds app (test)
JavaScript
1
star
48

loginn

A set of lambda functions and frontend components to aid authentication
JavaScript
1
star
49

create-pusher-app

An experiment with yeoman, hyperapp and the Pusher Feeds API
JavaScript
1
star
50

lukejacksonn

1
star