javascript – 在React Redux代码中有TypeError(0,_ColorReducer.color)不是函数错误

前端之家收集整理的这篇文章主要介绍了javascript – 在React Redux代码中有TypeError(0,_ColorReducer.color)不是函数错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我尝试从React& Redux第204页的书中实现示例,但是,有一个奇怪的问题 – 在React代码中有TypeError(0,_ColorReducer.color)不是函数错误

我有2个减速器用于一种颜色和颜色数组:

import React from "react";
import * as C from "./Constants";
import { color } from "./ColorReducer";

export const colorsReducer = (state = [],action) => {
  switch (action.type) {
    case C.ADD_COLOR:
      return [...state,color({},action)];
    case C.RATE_COLOR:
      return state.map(item => color(item,action));
    default:
      return state;
  }
};

import React from "react";
import * as c from "./Constants";

export const сolor = (state = {},action = {}) => {
  switch (action.type) {
    case c.ADD_COLOR:
      return {
        id: action.id,title: action.title,color: action.color,rating: action.rating
      };
    case c.RATE_COLOR:
      return state.id !== action.id
        ? state
        : {
            ...state,rating: action.rating
          };
    default:
      return state;
  }
};

所以,colorsReducer中的问题在哪里

return state.map(item => color(item,action));

完整的代码示例是here

你能帮我理解一下原因吗?

最佳答案
c字颜色是用其他语言..

猜你在找的JavaScript相关文章