'React Native arrow functions and 'if' statements

I have just been schooled on arrow functions, and how they can aid with visibility when you start using sub-functions on React Native and globally accessible objects.

I am not sure if this is different for "if" statements, but I can't get this to work at all. The issue:

myFunction() {
    console.log('Welcome Flag: ' + this.props.welcomeFlag);
    if (this.props.welcomeFlag == false) {
        this.props.dispatch(setWelcomeFlag(true));
        showMessage('Welcome back, ' + this.props.userName + '!', { duration: 3000 });
    }
}

In this example, the console logs the initial value of welcomeFlag, which is "false". I would then like to, if it is false, display a message to the user and set it to true. Super simple stuff.

It falls over here:

this.props.dispatch(setWelcomeFlag(true));

Because my if statement is not an arrow statement.

Except I can't get the arrow statement to work for if statements. It is working for other kinds of statements, but just not for these.

I have tried the answers listed here:

How to use if-else condition in arrow function in JavaScript?

But none of these work.

How can I fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source