ReactJS, bien débuter
Sylvain Combraque
Creator of Souin
Træfik helper
SkillValue speaker
Developer
@Darkweak
@Darkweak_dev
React history
Developed by Facebook
Started on late 2011
Opensourced on mid 2013
Jordan Walke et Pete Hunt
Javascript library
Advantages
Virtual DOM
Easy switch to RN
Powerful
Javascript only
Type everything
Exemple 👉
https://github.com/Darkweak/SacreeTech-reactjs
SSR ?
app.get('*', async (req: any, res: any) => {
let state = {};
const actions: any[] = [];
matchRoutes(
routes.map(r => ({
...r,
exact: true,
path: `/:language([a-z]{2})${r.path}`
})),
req.path
)
.map(
({ route }: any) =>
route.component?.getInitialProps ?
route.component.getInitialProps(req.path.split('/')) :
[]
)
.map(action => actions.push(...action));
await Promise
.all(actions)
.then((result: any) => result.forEach(
(r: any) => state = {...state, ...r}
)).catch(console.log);
const content = render({}, req.path, state);
res.send(content);
});
Item.getInitialProps = ([,,, slug]: [string, string, string, string]) => {
return [
new Conference()
.get({ id: slug })
.then(conference => ({
conference: {
[`${ conference.city }-${ conference.date }`]: conference
}
}))
];
};
<script>window.INITIAL_STATE = ${ JSON.stringify(state) }</script>
renderToString(
<BaseStoreProvider>
<StaticRouter location={path} context={context}>
<Switch>
{
routes.map(
(route: IRoute, index: number) => {
const Tag: any = route.component;
return (
<Route
key={index}
exact
path={'/' === route.path ? '' : route.path}
render={() => <LanguageProvider><Tag/></LanguageProvider>}
/>
)
})}
</Switch>
</StaticRouter>
</BaseStoreProvider>
);
import { ChunkExtractor } from '@loadable/server';
Chunking
Thanks for your attention
Questions
ReactJS, bien débuter - Sacrée Tech
By darkweak
ReactJS, bien débuter - Sacrée Tech
- 460