I am new to ReactJS and I recently came up with this redux date store that react uses mostly. I am trying to have a good grasp on it.
Just for the understanding purpose,
Maybe you can change this to see store change:
function getState() {
console.log(store.getState());
}
Just console.log(initialState.jsonData);
always show the origin data.
reducer
function always need to change the current statefunction reducer(state = initialState, action) {
console.log('reducer', state, action);
switch(action.type) {
case 'SEARCH':
const updatedPattern = new RegExp(action.payload.pattern)
return {
jsonData: state.jsonData.filter(item => updatedPattern.test(item.state))
};
default:
return state;
}
}
The key change is after: jsonData: state.jsonData.filter(item => updatedPattern.test(item.state))
store.subscribe(handleChange)
to get store changeconst unsubscribe = store.subscribe(getState)
use the store.subscribe
to auto get state change action like react-redux
does.