Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript

In development, persist application state across hot reloads.

Jason Millerd023263f57c2
diff --git a/global.d.ts b/global.d.ts
index b75bfdbf..7b9d325d 100644
--- a/global.d.ts
+++ b/global.d.ts
@@ -4,6 +4,10 @@ declare interface NodeModule {
hot: any;
}
+declare interface Window {
+ STATE: any
+}
+
declare namespace JSX {
interface Element { }
interface IntrinsicElements { }
diff --git a/src/components/app/index.tsx b/src/components/app/index.tsx
index 97cfada3..f958c5d7 100644
--- a/src/components/app/index.tsx
+++ b/src/components/app/index.tsx
@@ -36,6 +36,17 @@ export default class App extends Component<Props, State> {
enableDrawer = false;
+ constructor() {
+ super();
+ // In development, persist application state across hot reloads:
+ if (process.env.NODE_ENV === 'development') {
+ this.setState(window.STATE);
+ this.componentDidUpdate = () => {
+ window.STATE = this.state;
+ };
+ }
+ }
+
@bind
openDrawer() {
this.setState({ showDrawer: true });