freeCodeCamp/guide/chinese/certifications/front-end-libraries/react/render-react-on-the-server-.../index.md

490 B

title localeTitle
Render React on the Server with renderToString 使用renderToString在服务器上渲染React

使用renderToString在服务器上渲染React

解:

您将class传递给.renderToString()就像将组件传递给render方法一样。

class App extends React.Component { 
  constructor(props) { 
    super(props); 
  } 
  render() { 
    return <div/> 
  } 
 }; 
 
 // change code below this line 
 ReactDOMServer.renderToString(<App />);