gpt4 book ai didi

javascript - 创建 React 函数式组件时,使用粗箭头函数还是常规 ES5 函数更可取?

转载 作者:行者123 更新时间:2023-11-30 11:40:45 35 4
gpt4 key购买 nike

<分区>

在创建功能组件时哪个更可取?

这个

const Search = ({searchTerm, onChange, children}) => {
return (
<form>
{children}
<input
type='text'
value={searchTerm}
onChange={onChange}/>
</form>
);
}

function Search({searchTerm, onChange, children}) {
return (
<form>
{children}
<input
type='text'
value={searchTerm}
onChange={onChange}/>
</form>
);
}

Babel编译ES6版本为

var Search = function Search(_ref) {
var searchTerm = _ref.searchTerm,
onChange = _ref.onChange,
children = _ref.children;
};

ES5 版本编译为

function Search(_ref) {
var searchTerm = _ref.searchTerm,
onChange = _ref.onChange,
children = _ref.children;
};

对此有什么想法吗?

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