我尝试从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
你能帮助我理解原因吗?
答案 0 :(得分:3)
c中的单词颜色是其他语言..