I'm using react-native-router-flux with react-redux and I think that I should ask this question here, correct me if I'm wrong.
I have ActivityModal Container which I call to show up whenever there is an API call or similar thing where I want to show that modal. Currently I'm calling it like this:
Actions.refresh({key: 'activityModal', visible: true});
to show and
Actions.refresh({key: 'activityModal', visible: false});
to hide.
This works but I'd like rather to make some more elegant solution. I added two actions (for show and hide) and added there those lines of code and it works but I'm not sure if that's correct way to do it (and without using reducers, only action - i'm new to the redux). I'm thinking about another way to do this: adding some helper functions where I'll have those Actions.refresh calls and importing them where I need to access activityModal visibility.
Please tell me or suggest me what is the most correct way to do this?
Thanks!
edit: I succeeded but I'd like you to confirm if it's good practice. Here is what I did:
containers/LoginContainer.js
...
this.props.showActivityModal(); // calling this on button press
...
actions/activityModal.js
...
export function showActivityModal() {
return {
type: types.ACTIVITY_MODAL_SHOW,
payload: {}
}
}
...
reducers/activityModal.js
...
return {
visible: true,
text: ''
};
...
components/ActivityModal.js
...
class ActivityModal extends Component {
...
componentWillReceiveProps(nextProps) {
this.setState({
visible: nextProps.activityModal.visible
})
}
...
}
function mapStateToProps(state) {
return {
activityModal: state.activityModal
};
}
export default connect(mapStateToProps)(ActivityModal);
Thanks!