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

时间:2018-05-02 16:08:24

标签: javascript reactjs redux

我尝试从React& Redux第204页的书中实现示例,但是,有一个奇怪的问题 - There is TypeError (0 , _ColorReducer.color) is not a function error in React code

我有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

你能帮助我理解原因吗?

1 个答案:

答案 0 :(得分:3)

c中的单词颜色是其他语言..