【问题标题】:What does SS stand for in a React Component declaration?SS 在 React 组件声明中代表什么?
【发布时间】:2019-11-25 07:31:23
【问题描述】:

我在文档中没有看到任何关于 SS 的具体内容,我知道 P=props 和 S=state 但 SS?

编辑

对不起,我从一个 React+TypeScript 项目中引用了这个,即@types/react。我添加了typescript 标签。

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L395

【问题讨论】:

  • 能否提供您阅读本文的文档链接?

标签: reactjs typescript react-native


【解决方案1】:

它用于return value of getSnapshotBeforeUpdate,所以我打赌它代表SnapShot。

在 React 将 render 的结果应用于文档之前运行,并且 返回要提供给 componentDidUpdate 的对象。对储蓄有用 诸如render 之前的滚动位置之类的东西会导致它发生变化。

该文件中componentDidUpdate 的文档显示它接受名为快照的第三个参数:

仅当 getSnapshotBeforeUpdate 存在且返回非 null 时才会存在快照。

因此,SS 是用户定义的快照类型,由您的自定义实现 getSnapshotBeforeUpdate 返回,它被传递给 componentDidUpdate,因此您可以保留上次渲染的一些应用程序特定细节。

【讨论】:

    猜你喜欢
    • 2016-11-07
    • 2018-04-18
    • 1970-01-01
    • 2022-09-22
    • 1970-01-01
    • 2012-08-17
    • 2019-03-19
    • 2019-03-19
    • 2017-12-23
    相关资源
    最近更新 更多