【发布时间】:2019-05-07 23:02:36
【问题描述】:
我是 react-redux 的新手。
我确实有一个类似的对象,
const initialState = {
Low: [
{
id: 0,
technologyId: 0,
technology: '',
level: 'EASY'
}
],
Medium: [
{
id: 0,
technologyId: 0,
technology: '',
level: 'MEDIUM'
}
],
High: [
{
id: 0,
technologyId: 0,
technology: '',
level: 'TOUGH'
}
]
}
Now,
export default function QuizData(state = initialState, action) {
switch (action.type) {
case QUIZ_DATA:
return {
...state,
Low: action.data,
error: false,
}
case RESET_SETUP_QUIZ: {
console.log("intial state is ", ...state);
return {
...state
}
现在,这里发生的事情是在一些操作之后,这个对象随着每个键都有一些值而发生变化。喜欢,
{
Low: [
{
id: 0,
technologyId: 11,
technology: 'xsxs',
level: 'EASY'
}
],
Medium: [
{
id: 0,
technologyId: 22,
technology: 'swwsw',
level: 'MEDIUM'
}
],
High: [
{
id: 0,
technologyId: 110,
technology: 'xsxsx',
level: 'TOUGH'
}
]
}
所以,这会改变。现在,我想做的是,
当用户单击按钮时,我想将其更改为初始状态。
因此它不会有任何值,因为它应该与默认值相同。
所以,我试过了
return {
initalState
}
但在这里,初始状态也具有相同的值。
所以,我没有办法让它达到初始水平。
谁能帮我解决这个问题?
【问题讨论】:
标签: javascript reactjs redux react-redux reducers