gpt4 book ai didi

reactjs - React Native 内联样式和性能

转载 作者:行者123 更新时间:2023-12-03 13:11:56 25 4
gpt4 key购买 nike

执行以下操作:

<Text style={{color: 'blue', fontSize: 30}} />

与以下内容相比有任何性能影响:

<Text style={styles.blueButton} />

...

const styles = StyleSheet.create({
blueButton: {
color: 'blue',
fontSize: 30,
}
});

最佳答案

来自docs对于样式表

Performance:

  • Making a stylesheet from a style object makes it possible to refer to it by ID instead of creating a new style object every time.
  • It also allows to send the style only once through the bridge. All subsequent uses are going to refer an id (not implemented yet).

另一个好处是样式错误将在编译时而不是运行时生成。

我个人仍然喜欢使用内联样式(并为共享样式创建新组件),因为它使代码对我来说更具可读性,并且性能影响并不明显。

关于reactjs - React Native 内联样式和性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39336266/

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