在服务器端呈现期间调用getDerivedStateFromProps?

时间:2018-03-30 16:42:43

标签: reactjs

他们在react docs写道:

  

在实例化组件后调用getDerivedStateFromProps   以及当它收到新的道具时。

实例化是否与挂载相同?

所以我问是否

import { renderToString } from 'react-dom/server';

将调用此钩子。

1 个答案:

答案 0 :(得分:0)

This is easy enough to actually test. Simply call ReactDOMServer.render... with a component that has a getDerivedStateFromError and an error path in it's render function.

The idea behind getDerivedStateFromError is that it can be supported by the server side render pass.

It was added in 16.6.0 and but it is not yet supported by the server side render code. The primary reason for adding this is to enable error handling in async server side rendering code.