import { createStore, bindActionCreators, combineReducers } from 'redux';
import React from 'react';
import ReactDOM from 'react-dom';
//Reducer's
//Reducers will hold the fields of a table
//Reducers is a function returning the next state using previous state
//Reducers accept a state and an action
const userStatus = (state = {name: 'Michael'}, action) => {
//Checking the action type
switch(action.type){
case 'TOGGLE_STATUS':
return {...state, action.value}
default:
return state
}
}
//Stores's
const store = createStore(combineReducers({ User: userStatus }))
//Action's
const myvalue = 'Testing'
const changeStatus = (coolvalue) => ({
type: 'TOGGLE_STATUS',
value: coolvalue
}
)
//Dispatch actions
store.dispatch(changeStatus(myvalue));
console.log(store.getState());
我正在测试redux,我对一件事有些困惑。我试图返回一个新的对象,该对象的状态从操作中传入一些附加值。但是,当我在... action.value上使用spread运算符时,我得到一个对象,将字符串“ testing”分割成这样:
用户 : 0 : “ T” 1个 : “ e” 2 : “ s” 3 : “ t” 4 : “一世” 5 : “ n” 6 : “G” 名称 : “迈克尔”
我希望测试像User:'Testing'这样的User进行。 我尝试了行不通的action.value,有什么主意吗?