styfle/react-server-example-tsx
소개
⚛️ TypeScript에서 React 서버 사이드 렌더링을 사용하는 동형 웹 앱 보일러플레이트
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalreact-server-example-tsx
A complex example of how to do server-side rendering with React and TypeScript so that component code can be shared between server and browser (also known as isomorphic javascript).
Server-Side Rendering (SSR) leads to fast initial page loads, search-engine-friendly pages, and of course...its all type safe!
Getting Started
Clone the repo, change directory, install dependencies, build the code, and run it!
git clone https://github.com/styfle/react-server-example-tsx.git
cd react-server-example-tsx
npm install
npm run vercel-build
npm run test
npm start
Then navigate to http://localhost:3007 and click on the buttons to see some reactive events in action.
Preventing XSS
The original code from mhart attempts to sanitize the props by escaping and then inserting into a <script> tag.
I avoided this by performing 1 extra http request to fetch the props as json before initializing React in the browser. This means that click handlers will not be initialized until the data is returned and React can pick up where it left off after the server-side render and attach the click even handlers. This is the purpose of ReactDOM.hydrate.
See browser.tsx for the client-side code.
See server.ts for the server-side code.
Prior art
Based on prior work found at mhart/react-server-example. It's very good so you should check it out :)
Additionally, I use a combination between TypeScript Handbook and awesome-typescript-loader when I switched from browserify v1.4.x to webpack v2.0.x (now webpack v4.x).
Author
Developed by styfle, the author of Package Phobia
관련 프로젝트 살펴보기
불러오는 중…