I use next.js for my React application because it has server side rendering. When I checked the log, both methods ComponentWillMountand getInitialPropsare executed on the server side. So my question is: are there any differences between these methods? When should I run in ComponentWillMountand when should I run in getInitialProps. I do not see Next.JS mentions this.
ComponentWillMount
getInitialProps
GetInitialProps
GetInitialProps is usually an asynchronous function that is good forasynchronous operations on the server and passes data to the page as a props.
nextJs , Link, .
, .
lifecyle, render. .
, . , async. , , async.. , .
componentWillMount .
componentWillMount
componentWillMount() . render(), setState() . constructor(). - . componentDidMount(). , .
componentWillMount()
render()
setState()
constructor()
componentDidMount()
Source: https://habr.com/ru/post/1689751/More articles:Отсутствует общий размер страницы в Safari Web Inspector - safariDrop a few lines of pandas data using lambda - pythonHow to count the number of branches in a Java class - javaIonic 3 - ion-select (multiple) disables all parameters after selecting two elements - javascriptCompleted and failed downloads incorrectly return downloadItem.state from "in_progress" - firefoxJava Integer.MAX_VALUE vs Kotlin Int.MAX_VALUE - javaConvert string to integer hex value "Strange" behavior - javaПочему контексты OpenGL и CUDA являются жадной памятью? - windowsVisual Studio attribute binding attribute highlight [knockout.js] - visual-studioJava Generics creates a list of objects that extends class A and implements the B interface - javaAll Articles