next.js

Nextjs: ComponentWillMount vs getInitialProps

夙愿已清 提交于 2019-11-27 11:06:14
问题 I'm using next.js for my React app because it has server side rendering. As I checked by log, both methods ComponentWillMount and getInitialProps both run on server side. So my question is: Are there any differences between those method ? When should I run in ComponentWillMount and when should I run in getInitialProps . I don't see Next.JS mentions about this thing. 回答1: GetInitialProps GetInitialProps is a usually an async function which is good for asynchronous operations at the server and