fix: used selectors in mapstatetoprops
This commit is contained in:
committed by
Stuart Taylor
parent
08f737a0b9
commit
897b9110fc
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
import Media from 'react-media';
|
import Media from 'react-media';
|
||||||
import FCCSearch from 'react-freecodecamp-search';
|
import FCCSearch from 'react-freecodecamp-search';
|
||||||
|
|
||||||
@ -13,14 +14,16 @@ import './header.css';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
toggleDisplaySideNav,
|
toggleDisplaySideNav,
|
||||||
toggleDisplayMenu
|
toggleDisplayMenu,
|
||||||
|
displayMenuSelector
|
||||||
} from '../layouts/components/guide/redux';
|
} from '../layouts/components/guide/redux';
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = createSelector(
|
||||||
return {
|
displayMenuSelector,
|
||||||
displayMenu: state.guideNav.displayMenu
|
displayMenu => ({
|
||||||
};
|
displayMenu
|
||||||
};
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch =>
|
const mapDispatchToProps = dispatch =>
|
||||||
bindActionCreators({ toggleDisplaySideNav, toggleDisplayMenu }, dispatch);
|
bindActionCreators({ toggleDisplaySideNav, toggleDisplayMenu }, dispatch);
|
||||||
|
@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { StaticQuery, graphql } from 'gatsby';
|
import { StaticQuery, graphql } from 'gatsby';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
import { Grid, Col, Row } from '@freecodecamp/react-bootstrap';
|
import { Grid, Col, Row } from '@freecodecamp/react-bootstrap';
|
||||||
|
|
||||||
import SideNav from './components/guide/SideNav';
|
import SideNav from './components/guide/SideNav';
|
||||||
@ -13,7 +14,10 @@ import './guide.css';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
toggleExpandedState,
|
toggleExpandedState,
|
||||||
toggleDisplaySideNav
|
toggleDisplaySideNav,
|
||||||
|
displaySideNavSelector,
|
||||||
|
displayMenuSelector,
|
||||||
|
expandedStateSelector
|
||||||
} from './components/guide/redux';
|
} from './components/guide/redux';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
@ -40,13 +44,16 @@ const propTypes = {
|
|||||||
toggleExpandedState: PropTypes.func
|
toggleExpandedState: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = createSelector(
|
||||||
return {
|
displaySideNavSelector,
|
||||||
expandedState: state.guideNav.expandedState,
|
displayMenuSelector,
|
||||||
displayMenu: state.guideNav.displayMenu,
|
expandedStateSelector,
|
||||||
displaySideNav: state.guideNav.displaySideNav
|
(displaySideNav, displayMenu, expandedState) => ({
|
||||||
};
|
displaySideNav,
|
||||||
};
|
displayMenu,
|
||||||
|
expandedState
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch =>
|
const mapDispatchToProps = dispatch =>
|
||||||
bindActionCreators({ toggleExpandedState, toggleDisplaySideNav }, dispatch);
|
bindActionCreators({ toggleExpandedState, toggleDisplaySideNav }, dispatch);
|
||||||
|
@ -19,6 +19,10 @@ export const toggleExpandedState = createAction(types.toggleExpandedState);
|
|||||||
export const toggleDisplaySideNav = createAction(types.toggleDisplaySideNav);
|
export const toggleDisplaySideNav = createAction(types.toggleDisplaySideNav);
|
||||||
export const toggleDisplayMenu = createAction(types.toggleDisplayMenu);
|
export const toggleDisplayMenu = createAction(types.toggleDisplayMenu);
|
||||||
|
|
||||||
|
export const displaySideNavSelector = state => state[ns].displaySideNav;
|
||||||
|
export const displayMenuSelector = state => state[ns].displayMenu;
|
||||||
|
export const expandedStateSelector = state => state[ns].expandedState;
|
||||||
|
|
||||||
export const reducer = handleActions(
|
export const reducer = handleActions(
|
||||||
{
|
{
|
||||||
[types.toggleExpandedState]: (state, { payload }) => ({
|
[types.toggleExpandedState]: (state, { payload }) => ({
|
||||||
|
Reference in New Issue
Block a user