gpt4 book ai didi

javascript - react : What is the naming convention to inform the return type of the function is jsx in the comments?

转载 作者:行者123 更新时间:2023-12-03 09:40:23 24 4
gpt4 key购买 nike

我相信大多数开发人员都遵循 JSDocs 推出的关于在 JavaScript 中进行注释的指南。因此,这就是我通常为我创建的函数提供注释的方式,以帮助可能处理同一文件的其他开发人员:

  /**
* Renders the translated section in sidebar.
*
* @param {array} langList - List of languages to be rendered
* @param {boolean} isTranslated - If true render translations
* @return {JSX} - Returns JSX
*/
_renderLangSection (langList, isTranslated) {
return (
<div>{isTranslated ? langlist : null}</div>
);
}

如您所见,此函数的返回类型是 JSX。这是正确的返回类型吗?或者 React element 是一个更好的名字吗?有谁知道 React 社区喜欢什么?

最佳答案

如果调用返回类型为 JSX 并不重要,因为在使用 Babel 编译此函数后,JSX 代码将转换为纯 javascript

function _renderLangSection (langList, isTranslated) {
return React.createElement("div", null, isTranslated ? langlist : null);
}

最终返回一个 React 元素。

关于javascript - react : What is the naming convention to inform the return type of the function is jsx in the comments?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572459/

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