I\'m reading the React Native docs / tutorial, and I\'m wondering what the point of the StyleSheet.create
function is.
For example, the tutorial has the
StyleSheet.create
does not add performance gains anymore.
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/29265#issuecomment-430783289
quoting the github comment:
@alloy I understand what docs says, but can prove that code:
const myStyle: ViewStyle = { flex: 1 } export const FlexView: React.SFC = (props) =>
{props.children} has almost same performance (even slightly faster) compared to
const s = StyleSheet.create({ flex: { flex: 1 } }) export const FlexView: React.SFC = (props) =>
{props.children} because if you look at sources, you discover that latest chunk effectively extracted to this (see: https://github.com/facebook/react-native/blob/0.57-stable/Libraries/StyleSheet/StyleSheet.js#L373):
const s = { flex: { flex: 1 } } export const FlexView = (props) =>
{props.children} And yes, in previous versions of RN it was global registry of styles, but it was even more slow, because it never crossed bridge border actually (proof from 0.55 branch)