React Redux 箭头函数未编译

React Redux arrow function not compiling

我用 npx create-react-app my-app --template redux 创建了新的 React&Redux 项目。

从下面的代码我得到以下错误:Parsing error: Invalid parenthesized assignment pattern.

将箭头函数切换为表达式后一切正常。

import { createSlice } from '@reduxjs/toolkit';

export const movieSlice = createSlice({
  name: "movie",
  initialState: { value: { title: "", descripion: "" } },
  reducers: {
    getMovies: (state, action) = () => {
      state.value = action.payload;
    }
  }
});

export default movieSlice.reducer;

我猜你错误地添加了额外的 () =。这是解决方案

import { createSlice } from '@reduxjs/toolkit';

export const movieSlice = createSlice({
  name: "movie",
  initialState: { value: { title: "", descripion: "" } },
  reducers: {
    getMovies: (state, action) => {
      state.value = action.payload;
    }
  }
});

export default movieSlice.reducer;