React beginner, ask for help how to understand this code?

< H1 > question 1 < / H1 >

what is the difference between the following two pieces of code, and why one uses ({}) and the other does not use

toggleTodo = id => ({
    type: "TOGGLE_TODO",
    id
});
toggleToChange = (id)=> {
    return {
        type: "TOGGLE_TO_CHANGE",
        id
    }
};
< H1 > question 2 < / H1 >
this.setState({
            showPageGroup: showPageGroup,
            showPageNumber: showPageNumber,
            ellipsisNumber: ellipsisNumber,
            endGetIndex: endGetIndex,
            arrowShow: arrowShow,
            userKeyValue: userKeyValue
        })

how does this setState, optimize merging?

Apr.30,2021

  1. there is no difference between the two pieces of code, both of which define a method that returns an object. The difference lies in the understanding of the arrow function. If the arrow function needs to execute more than one statement, it needs to be wrapped in curly braces. However, curly braces will be considered a literal amount of an object, which will conflict. So when you need to return the literal amount of the object directly, you can enclose it with (), or you can display the return in {}.

2.

this.setState({
            showPageGroup,
            showPageNumber,
            ellipsisNumber,
            endGetIndex,
            arrowShow,
            userKeyValue
        })
Menu