Skip to content

Instantly share code, notes, and snippets.

@bisubus
Forked from lixiaoyan/entry.js
Created September 24, 2017 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bisubus/6b6a197fa4eccb67e2940c60b10efaa1 to your computer and use it in GitHub Desktop.
Save bisubus/6b6a197fa4eccb67e2940c60b10efaa1 to your computer and use it in GitHub Desktop.
React 16: ReactDOM.hydrate(...)
import React from "react";
import ReactDOM from "react-dom";
import { AppContainer } from "react-hot-loader";
import App from "./App";
const render = (hydrate = false) => {
const container = document.querySelector("#app");
const element = (
<AppContainer>
<App />
</AppContainer>
);
if (hydrate) {
ReactDOM.hydrate(element, container);
} else {
ReactDOM.render(element, container);
}
};
render(true);
if (module.hot) {
module.hot.accept(() => {
render();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment