Last active
August 18, 2020 06:44
-
-
Save mrpeski/2f3889085b2a0fbdfd2f42da176cbf77 to your computer and use it in GitHub Desktop.
mapState
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
import React, { useEffect } from 'react'; | |
import { connect } from 'react-redux'; | |
import CardComponent from '../../common/ui/CardComponent'; | |
import ContractsTable from './ContractsTable'; | |
import { loadMany, selectors } from './slice'; | |
function ContractList(props: any) { | |
const { list, currentPage, query: queryString, filters, dispatch } = props; | |
useEffect(() => { | |
if (list.length == 0) { | |
dispatch(loadMany(currentPage, queryString, filters)); | |
} | |
}, [queryString, currentPage, filters, list]); | |
return ( | |
<CardComponent icon="file-contract" header="Contracts"> | |
<ContractsTable contracts={list} /> | |
</CardComponent> | |
) | |
} | |
const mapState = (state: { contract: any; }, props: any) => { | |
let { contract: { currentPage, filters, query, store }} = state; | |
// const filterString = serlializefilters(filters, query); | |
return { | |
list: Object.values(store), | |
currentPage: selectors.currentPageSelector(state), | |
query: selectors.queryStringSelector(state), | |
filters: selectors.filtersSelector(state) | |
}; | |
}; | |
export default connect(mapState)(ContractList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment