question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[HELP] how to handle react-perf/jsx-no-new-object-as-prop while passing array of styles to react native component?

See original GitHub issue

So, considering the code below, which is supposedly popular in react-native, how should I re-design my code to remove the warning?

<Text
              style={[
                styles.smallBoldText,
                styles.greenText,
                styles.greenBackground,
              ]}>
              Some Text
</Text>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bolatovumarcommented, Jan 26, 2021

@TheSolly I don’t know anything about React Native specifically but in the web version of react you could either create a constant outside of the component if these are all just static properties. If styles is passed as a prop or something you could use useMemo to memoize this array.

0reactions
douglasjuniorcommented, Jul 26, 2021

Here we use with useMemo:

const textStyles = useMemo(() => [
                styles.smallBoldText,
                styles.greenText,
                condition ? styles.greenBackground : null,
], [condition]);


return (
    <Text
              style={textStyles}>
              Some Text
    </Text>
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Style - React Native
With React Native, you style your application using JavaScript. All of the core components accept a prop named style. The style names and...
Read more >
Passing Functions to Components - React
There are several ways to make sure functions have access to component ... Make sure you aren't calling the function when you pass...
Read more >
Pass style array to React Component - Stack Overflow
I want to pass an array of styles to a React Component using postcss-loader and css modules. My webpack.config.file for compiling css files...
Read more >
Styles - 30 Days of React Native - Fullstack.io
React Native lets us pass an array of styles to a component to accomplish the same thing. When we pass an array of...
Read more >
How To Style React Components | DigitalOcean
In this tutorial, you'll learn three different ways to style React components: plain Cascading Style Sheets (CSS), inline styles with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found