N
N
Ninja Mate2017-09-01 21:29:22
JavaScript
Ninja Mate, 2017-09-01 21:29:22

Is return necessary in ES6 syntax?

Need help understanding es6
Arrow functions have the option not to write return

export const receive = () => ({
    type: actions.SET
})

It looks very nice, but how to do it on more complex examples, where you still need to perform some actions before return
export const onSubmit = (data, token) => {

    axios.defaults.headers.common['Authorization'] = token;

    return dispatch => (
        axios.post(apiUrl + '/pss', data)
            .then(res => {

                if (res.data !== null) dispatch(onSubmitSuccess())
                else return { type: psActions.ON_SUBMIT_ERROR }

            })
    )
    
}

I would be happy to provide a detailed explanation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Shashenkov, 2017-09-01
@victorzadorozhnyy

What's the problem. 1 line - return is not needed. A lot, write explicitly return. Or is it hard to press 6 keys? Do you write code for yourself or for those who will then dance with a tambourine?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question