the specific scenarios are as follows:
// reducer.js
const initialState = {
test: [
{
id: 1
show: true
},
{
id: 2
show: true
},
{
id: 3
show: true
}
]
}
export function testUp(state=initialState, action) {
switch (action.type) {
case UPDATE: {
return {
...state,
// ...action.payload, cidList
takeCidList(state.test, action.payload)
}
}
default:
return state
}
}
function takeCidList(test, cidList) {
const list = []
// todo get initialState.test
return list
}
// test.jsx
class Test extends Component {
// ...
updateTestState = idList => {
this.props.updateTestState(idList)
// idList = [1,4,6,8] id
}
}
export default connect(null, {updateTestState})(Test)
// action.js
export const updateTestState = idList => ({type: UPDATE, payload: idList})
To put it simply, I am what I got in the react component is an array of id. What I need to do is to find out that the id in the test array in state is equal to [1 code 2 show 3 code 4] and change their false
field to . So where should such a step be done?
in test.jsx? So I need to get the state of test in test.jsx. And is it really good to handle data in a container component?
in reducer.js? It doesn"t feel pure enough, huh?