Which one is a better approach 1st or 2nd in terms of performance ?
const getCookieValue = readCookie('my_var')
should be declared at top or since its usage is only in a condition so better to keep it inside if
statement
Approach 1
componentWillMount() {
const {data1, data2} = this.props
if(data1) {
const getCookieValue = readCookie('my_var')
if(getCookieValue === 'test_string') {
// Statements ....
}
}
}
OR
Approach 2
componentWillMount() {
const {data1, data2} = this.props
const getCookieValue = readCookie('my_var')
if(data1) {
if(getCookieValue === 'test_string') {
// Statements ....
}
}
}