Skip to content

Instantly share code, notes, and snippets.

@mrpeski
Last active August 18, 2020 06:44
Show Gist options
  • Save mrpeski/2f3889085b2a0fbdfd2f42da176cbf77 to your computer and use it in GitHub Desktop.
Save mrpeski/2f3889085b2a0fbdfd2f42da176cbf77 to your computer and use it in GitHub Desktop.
mapState
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