From the docs for
- 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).
Another benefit is that style errors will be generated at compile time as opposed to run time.
I personally still like using inline styles (and creating new components for shared styles) because it makes the code more readable for me and the performance hit has not been noticeable.
Yes it will help performance slightly. That's not really what matters, though.
There are many ways to improve performance such that the increase in performance is so slight that no human would ever notice it while using your app, in which case there's no real benefit to said performance improvement.
So the question is really whether or not it improves performance enough to where it's noticeable. The answer to that is "almost definitely not", unless you're constantly rendering hundreds/thousands of components each with inline styles at the same time (which should never happen).
Inline styles plus style utility components are what I prefer because they're faster to write and they're more maintainable (easier to make changes to the correct style because you can find the style for the component you're wanting to change more easily). Plus you don't have to arbitrarily give things names which is a lot of sunk time/effort.
As mentioned in the comments of the selected answer, the performance comment has been removed from the RN docs, but in my project (a mobile game using RN that uses multiple active Animated components), using
Stylesheet instead of inline styles helps performance.
My main view where around 5~10 Animated components are active, the UI FPS drops to 15~18 when I use inline styles, but if I use Stylesheet it has a 60fps with little to no stagger. Note that I had to implement this in most components especially the Animated components and its child components in order to see the improvements, I still have some inline styles lying around in other components.
When it comes to performance, your UI FPS is affected by your js activity. So reducing/optimizing JS load will help to keep your FPS perform better. In my project, some style values are computed, but they only need to be computed during the initial load. When I use inline styles, these values are computed every re-render, so using stylesheets makes more sense since there will be no recomputing. This is especially important when handling image assets.
Bottom line, use Stylesheet when you can. It will help in the long run and avoid any unnecessary updates from inline to stylesheet.
- React Native inline styles and performance
- Building hybrid React apps for iOS and Android with native performance
- How to Center React Component Horizontally and Vertically Using Inline Styles
- Setting inline styles in React using strings and not CSSProperties
- React - How to pass clases and inline styles as props in
- What is the difference between React Native and React?
- Setting a backgroundImage With React Inline Styles
- Simulate display: inline in React Native
- React renderToString() Performance and Caching React Components
- !important inline styles in react
- React Native / Xcode Upgrade and now RCTConvert.h not found
- React native: How to combine external and inline styles?
- Setting Complex react inline styles such as hover, active on react components such as button
- React Native 0.64 won't build iOS app after updating Xcode to 12.5 and iOS to 14.5
- react native show current time and update the seconds in real-time
- TouchableOpacity and button not working in react native Modal?
- Can we share code between react webapp and react native app and is react-native production ready
- How in React native destroy an component instance to avoid memory leak and release underlie views objects of native code?
- React Native - What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()?
- Clone and run react native projects from GitHub
- Typescript path mapping for React Native *.android.ts and *.ios.ts modules
- React Native alignSelf center and stretch to maxWidth?
- Performance issues with a tree structure and shouldComponentUpdate in React / Redux
- react native post form data with object and file in it using axios
- How to use vw and vh css with React Native
- Adding inline styles to react
- How to write inline styles in react
- How to drag and sort in React Native
- React Native and Https Agent
More Query from same tag
- How to pass JSON to SwaggerUIBundle?
- how to get the value of a map returned button in react
- React State Button Click is Behind
- trying to map an array out of backend API in REACT
- Click OutSide co close sidebar reactjs
- How to get url in getstaticpath nextjs
- How to pass string parameter to nested function, which has already parameters?
- Enter text into multi stacked donut chart
- Specifying array of functions with unknown arguments throws a typeerror
- Unable to dispatch an action in react-redux using typescript
- Cannot read property 'map' of undefined in ReactJS
- Why is my functional component's state undefined?
- Reactjs, Generate JSX element from array using map
- Material Table - Editable Cell Validation
- isomorphic/universally-rendered React 15 app breaks with Cloudflare HTTP Proxy ("orange cloud")
- whay when clicking on my modal, the model disappears
- React create one styled components for two different icons?
- React Router v6 redirect with Params and SearchParams
- save the previous state to one array in ReactJS
- Randomly position divs that fade in and out
- Getting error net::ERR_NAME_NOT_RESOLVED while axios get/post request in my react project
- How to structure Department-Employee data
- React: state not updating on first click
- What is precisely a "Side Effect" in redux other than async operations?
- React check how many times a component re-renders
- React - How to wait for component props
- why grid- "column: span 2;" does not change the size of the buttons?
- In React, why does adding state that is a number to prop that is a number results in string?
- Unable to modify children in parsed html