Skip to content

Commit

Permalink
use useSelector mult times returning a single field
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 committed Mar 26, 2020
1 parent b524eac commit 0b76601
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 2 additions & 4 deletions app/components/layout/TabbedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ function animatedStyles(styles, dir) {
}

function TabbedPage(props) {
const { location, uiAnimations } = useSelector(state => ({
location: sel.location(state),
uiAnimations: sel.uiAnimations(state)
}));
const location = useSelector(sel.location);
const uiAnimations = useSelector(sel.location);
const [ matchedTab, setMatchedTab ] = useReducer(() => getMatchedTab(location, props.children));

const previous = usePrevious({ matchedTab, location });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ async function onLoadMoreProposals(proposals, inventory, getProposalsAndUpdateVo

export function ProposalList ({ finishedVote, tab }) {
const [ noMoreProposals, setNoMore ] = useState(false);
const { proposals, inventory } = useSelector(state => ({
proposals: sel.proposals(state),
inventory: sel.inventory(state),
loading: sel.getProposalsAttempt(state)
}));
const proposals = useSelector(sel.proposals);
const inventory = useSelector(sel.inventory);
const dispatch = useDispatch();
const getProposalsAndUpdateVoteStatus = (proposalBatch) => dispatch(gov.getProposalsAndUpdateVoteStatus(proposalBatch));
const [ state, send ] = useMachine(fetchMachine, {
Expand Down
13 changes: 5 additions & 8 deletions app/components/views/GovernancePage/Proposals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ function getProposalsTab(location) {
}

function Proposals() {
const {
activeVoteCount, preVoteCount, location, politeiaEnabled
} = useSelector(state => ({
politeiaEnabled: sel.politeiaEnabled(state),
activeVoteCount: sel.newActiveVoteProposalsCount(state),
preVoteCount: sel.newPreVoteProposalsCount(state),
location: sel.location(state)
}));
const activeVoteCount = useSelector(sel.newActiveVoteProposalsCount);
const preVoteCount = useSelector(sel.newPreVoteProposalsCount);
const politeiaEnabled = useSelector(sel.politeiaEnabled);
const location = useSelector(sel.location);

// TODO move reducers which only control local states from reducer/governance.js
// to here.
const [ tab, setTab ] = useReducer(() => getProposalsTab(location));
Expand Down

0 comments on commit 0b76601

Please sign in to comment.