i do have a react class component with state in it.
class NewComponent extends Component {
state = {
modalIsOpen: false,
aa: true,
bb: false,
cc: false,
dd: false,
ee: 1,
dd: [],
cc: [],
ff: [],
gg: [],
vv: [],
bb: '',
rr: '',
bb: '',
axcx: 'recent',
zxc: null,
asd: [],
qwe: '',
asd: '',
xc: false,
wxc: false,
zxcc: null,
zxcxzc: [],
zxc: {},
zxc: false,
zxc: [],
zxc: null,
zxc: '',
imgGroup: aa.imgGroup,
videoGroup: xx.videoGroup,
docGroup: vv.docGroup,
}
}
is it possible to store these state somewhere in store and import it to this component.if so can you guys please help me to do so. am new to redux.
Any help will be highly helpful
This could be done easily. What you have to do is add those variables in your reducer to a respective store (let call the store as youstore).
Reducer.js
const initialState = {
modalIsOpen: false,
aa: true,
bb: false,
cc: false,
dd: false,
ee: 1,
dd: [],
cc: [],
ff: [],
gg: [],
vv: [],
bb: '',
rr: '',
bb: '',
axcx: 'recent',
zxc: null,
asd: [],
qwe: '',
asd: '',
xc: false,
wxc: false,
zxcc: null,
zxcxzc: [],
zxc: {},
zxc: false,
zxc: [],
zxc: null,
zxc: ''
}
export default (state = initialState, action) => {
switch (action.type) {
case SOME_ACTION:
......
}
Now, this should be available from your component as props. For this should use mapStateToProps method.
Your_component.jsx
const mapStateToProps = state => {
return {
modalIsOpen: state.youstore.modalIsOpen,
aa: state.youstore.aa,
bb: state.youstore.bb,
cc: state.youstore.cc,
dd: state.youstore.dd,
.......
};
};
const mapDispatchToProps = dispatch => {
return {
someMethod: data => dispatch(somemethod(data)),
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(your_Component);
To change the value of a state you have to dispatch an action through mapDispatchToProps