Using createSlice() with Async Action Creators Parenthesis use

In the usersSlice.js there are extraReducer’s promise lifecycle states and their resolution instructions for fetchUserById, but after the arrow there are parenthesis and the curly braces used together. Whereas, in allRecipesSlice.js the final solution requires that we call the three lifecycle states without the parenthesis.

What made the difference between the two createAsyncThunk functions in how they can be returned in extraReducers? Is it the fact fetchUserById requires a function passed to it, and loadRecipes does not?


I think it is just a stylistic difference. If you delete the extra parenthesis in the lesson the code runs exactly the same. I also copied the userSlice.js content into VSCode, and it highlighted that part as incorrect. Once I removed the extra parentheses, everything was fine. So according to ESLint, without parentheses is better style.

1 Like