gpt4 book ai didi

javascript - 返回 JSX 的 React 类方法的流注释

转载 作者:行者123 更新时间:2023-12-03 00:51:03 29 4
gpt4 key购买 nike

虽然我确实喜欢在 JavaScript 应用程序中进行类型检查的想法,但使用 Flow 严重减慢了我的速度,因为我似乎无法找到基本问题的答案。我发现官方文档在某些情况下很有用,但说实话很令人困惑。

这是我正在寻找的内容:我有一个基于类的 React 组件(使用 React Native),其中有一个执行一点逻辑的方法,然后在最后返回一些 JSX。

renderUpdatedAt = (): React.Element<typeof View> => {
...Other Logic

const updatedAt = max(updatedTimes);

let updatedAtText = updatedAt
? `Insights are updated daily. Last updated ${moment(updatedAt).format(
'M/D/YY, h:mma',
)}`
: 'Insights are updated daily.';

return (
<View style={styles.updatedAt}>
<BodyMicro style={styles.updatedAtText}>{updatedAtText}</BodyMicro>
</View>
);
};

它最终返回一个 View 组件,该组件与 React Native 一起开箱即用。正如您所看到的,我的印象是我会使用 React.Element 注释该方法

有谁知道这应该如何注释?也许我做得对吗?目前还不确定。

最佳答案

如果您返回的只是 View那么是的React.Element<typeof View>是正确的。

关于javascript - 返回 JSX 的 React 类方法的流注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53040246/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com