Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

What's better? Create a variable or pass the parameter directly?

$
0
0

I'm studying ReactJS and there are some (simple) questions that I can't find the answer to.

For example, I have a component that sends a property to another component. To pass this property I have two alternatives. Create a constant, or just pass the property. Follow the examples

const Component1 = ({ param }) => {      return <AnyOtherComponent otherComponentParam={param ? 'name1' : 'name2'} />    }    export default Component1

------------------------------- // ----------------------------------- // ---------------------

const Component2 = ({ param }) => {  const otherParam = param ? 'name1' : 'name2'  return <AnyOtherComponent2 otherComponentParam={otherParam} />}export default Component2

Assuming I only use this constant to pass the property, ie I only use it once, what would be better?Create this constant variable or pass the property directly as in the first example?

I think example 1 is the most correct, as I'm not allocating memory space to a variable that will only be used once. But I didn't find any text/article that makes this comparison


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>