Skip to content

Commit fa49550

Browse files
committed
update TS SSR example
1 parent 5835d6a commit fa49550

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

examples/SSR/typescript-react/app/App.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
import * as React from "react";
2-
import {Helmet} from "react-helmet";
3-
//import { Switch, Route, Redirect } from "react-router-dom";
42
import Home from "./components/Home";
53
import importedComponent, {ComponentLoader, loadableResource} from "react-imported-component";
64

7-
const Another = importedComponent(() => import(/* webpackChunkName: namedChunk-0 */"./components/Another"));
5+
const Another = importedComponent(() => import(/* webpackChunkName: namedChunk-0 */"./components/Another"), {
6+
LoadingComponent: () => <div>loading</div>
7+
});
88
const Other1 = importedComponent(() => import(/* webpackChunkName: "namedChunk-1" */"./components/Other"));
99
const Other2 = importedComponent(() => import(/* webpackChunkName: "namedChunk-1" */"./components/OtherTween"));
1010

11-
importedComponent(() => import(/* webpackChunkName: namedChunk-0 */"./components/Another"), {
12-
render(Component, state) {
13-
if (state.state === "loading") {
11+
const AnotherWrapped = importedComponent(() => import(/* webpackChunkName: namedChunk-0 */"./components/Another"), {
12+
render(Component, state, props: {prop: number}) {
13+
if (state === "loading") {
1414
return <span/>
1515
}
16-
return <div><Component/></div>
16+
return <div className="wrapped"><Component test={props.prop} p2={props.prop}/></div>
1717
}
1818
});
1919
//import Another from "./components/Another";
2020

2121
export default function App() {
2222
return (
2323
<div>
24+
[not-trackable]
2425
<ComponentLoader
2526
loadable={() => import('./components/Another')}
2627
/>
2728
<ComponentLoader
2829
loadable={loadableResource(() => import('./components/Another'))}
2930
/>
30-
<Helmet defaultTitle="Hello World!">
31-
<meta charSet="utf-8"/>
32-
</Helmet>
33-
<Home/>
34-
<Another/>
35-
<Other1/>
31+
[/not-trackable]
32+
[home]<Home/>[/home]
33+
<Another test={42} p2={42}/>
34+
[
35+
<AnotherWrapped prop={24}/>
36+
]
37+
<Other1 test={42}/>
3638
<Other2/>
3739
<Home/>
3840
</div>

examples/SSR/typescript-react/app/client.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rehydrateMarks } from "react-imported-component";
2-
import React from "react";
2+
import * as React from "react";
33
import ReactDOM from "react-dom";
44
import { BrowserRouter } from "react-router-dom";
55
import { Provider } from "react-redux";
@@ -14,6 +14,7 @@ delete window.__PRELOADED_STATE__;
1414
const store = configureStore(preloadedState);
1515

1616
const element = document.getElementById("app");
17+
1718
const app = (
1819
<Provider store={store}>
1920
<BrowserRouter>
@@ -23,5 +24,7 @@ const app = (
2324
);
2425

2526
rehydrateMarks().then(() => {
27+
console.log(element.innerHTML);
2628
ReactDOM.hydrate(app, element);
29+
console.log(element.innerHTML);
2730
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import React from "react";
22

3-
const Another = () => <a>Another!</a>;
3+
const Another:React.SFC<{test: number, p2: number}> = () => <a>Another!</a>;
44
export default Another;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import * as React from "react";
22

3-
const Another = () => <a>Other!</a>;
3+
const Another:React.SFC<{test: number}> = () => <a>Other!</a>;
44
export default Another;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import React from "react";
22

3-
const Another = () => <a>Other!</a>;
3+
const Another: React.SFC = () => <a>Other!</a>;
44
export default Another;

examples/SSR/typescript-react/app/imported.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
import {assignImportedComponents} from 'react-imported-component';
33
const applicationImports = {
4-
0: () => import(/* webpackChunkName: namedChunk-0 */'./components/Another'),
4+
0: () => import('./components/Another'),
55
1: () => import(/* webpackChunkName: "namedChunk-1" */'./components/Other'),
66
2: () => import(/* webpackChunkName: "namedChunk-1" */'./components/OtherTween'),
77
};

0 commit comments

Comments
 (0)