Should i create a variable or pass the parameter directly?

Viewed 28

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

I would like to have access to the texts of articles that talk about the serial subjects and better facts about which

0 Answers
Related