Skip to content

Commit

Permalink
fix hooks in server code, change descripton
Browse files Browse the repository at this point in the history
  • Loading branch information
Kallenju committed Dec 6, 2022
1 parent 9d6fb26 commit 311d039
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const { NODE_ENV } = process.env;

module.exports = {
entry: path.resolve(__dirname, '../src/server/server.ts'),
entry: path.resolve(__dirname, '../src/server/server.tsx'),

output: {
path: path.resolve(__dirname, '../dist/server'),
Expand Down
6 changes: 5 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "template-for-react-ts-ssr-hmr",
"version": "1.0.0",
"description": "Template for a project with React, TypeScript, SSR, HMR",
"version": "1.0.1",
"description": "Template for a project with React, TypeScript, SSR, HMR. Template imply using CSS Modules and Stylus. But it can be easily changed.",
"repository": {
"type": "git",
"url": "https://github.com/Kallenju/template-for-react-ts-ssr-hmr.git"
Expand Down
5 changes: 3 additions & 2 deletions src/server/server.ts → src/server/server.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import ReactDOM from 'react-dom/server';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import Header from '../shared/Header';
import indexTemplate from './indexTemplate';

Expand All @@ -8,7 +9,7 @@ const app = express();
app.use('/static', express.static('./dist/client'));

app.get('/', (req, res) => {
res.send(indexTemplate(ReactDOM.renderToString(Header())));
res.send(indexTemplate(ReactDOMServer.renderToString(<Header />)));
});

app.listen(3000);
9 changes: 8 additions & 1 deletion src/shared/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React from 'react';
import React, { useState } from 'react';
import styles from './header.module.styl';

export default function Header(): React.ReactElement {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
}
return (
<header>
<h1 className={styles.example}>Hello React</h1>
<button className={styles.example} onClick={handleClick}>
Clicked {count} times
</button>
</header>
);
}

0 comments on commit 311d039

Please sign in to comment.