K
K
KnightForce2018-04-15 17:22:35
JavaScript
KnightForce, 2018-04-15 17:22:35

React Native. Variables in render and memory?

Two options:
1)

class MyClass extends Component {
 constructor(props) {
   //...
 }
 render {
  let {a} = this.props.a
  return <Text>{a}</Text>
 }
}

2)
class MyClass extends Component {
 constructor(props) {
   //...
 }
 render {
  return <Text>{this.props.a}</Text>
 }
}

The examples are contrived, but the question is, what is more expensive, to create a variable on each render and perform destructuring, or to refer to the property of the object, instead of passing a reference to the value to the variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
khorark, 2018-04-16
@KnightForce

There is such a statement - "premature optimization is the root of all evil." There is no need to do this if you do not see the difference in performance on your own example, therefore, in terms of performance, it does not matter which solution you use.
From the point of view of code readability, it is better to do destructuring, as it turns out more visually.
PS Correctly do let { a } = this.props

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question