Last active
March 8, 2018 09:13
-
-
Save sbycrosz/06a0776b421a7759d44a5d82d9656c7c to your computer and use it in GitHub Desktop.
SimpleReducer_ConnectedComponent.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api/selectors.js | |
import _ from 'lodash'; | |
export const createLoadingSelector = (actions) => (state) => { | |
// returns true only when all actions is not loading | |
return _(actions) | |
.some((action) => _.get(state, `api.loading.${action}`)); | |
}; | |
// components/todos/index.js | |
import { connect } from 'react-redux'; | |
import Todos from './Todos'; | |
import { createLoadingSelector } from '../../redux/api/selectors'; | |
// Show loading on GET_TODOS_REQUEST | |
const loadingSelector = createLoadingSelector(['GET_TODOS']); | |
const mapStateToProps = (state) => ({ isFetching: loadingSelector(state) }); | |
export default connect(mapStateToProps)(Todos); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment