simplify props with withRouter
This commit is contained in:
parent
ea3d340dc2
commit
c2f48865b7
2
dist/global-bundle.js
vendored
2
dist/global-bundle.js
vendored
File diff suppressed because one or more lines are too long
6
dist/main-bundle.js
vendored
6
dist/main-bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import { RouteComponentProps, withRouter } from 'react-router-dom';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
@ -127,9 +127,6 @@ class PokemonApp extends React.Component<IConnectedPokemonAppProps, IState> {
|
||||
attackTypeEffectiveness={ attackTypeEffectiveness }
|
||||
combatMoves={ combatMoves }
|
||||
toggleInterruption={ this.handleToggleInterruption }
|
||||
history={ this.props.history }
|
||||
location={ this.props.location }
|
||||
match={ this.props.match }
|
||||
/>
|
||||
<Footer />
|
||||
</div>
|
||||
@ -194,20 +191,4 @@ const mapStateToProps = (state : PokemonAppProps) : PokemonAppProps => {
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch : IPokemonAppDispatch['dispatch']) : IPokemonAppDispatch => {
|
||||
return {
|
||||
dispatch
|
||||
};
|
||||
};
|
||||
|
||||
const mergeProps = (state : PokemonAppProps, dispatchProps : IPokemonAppDispatch, ownProps : IRouterProps) : IConnectedPokemonAppProps => {
|
||||
return {
|
||||
...state,
|
||||
...dispatchProps,
|
||||
history: ownProps.history,
|
||||
location: ownProps.location,
|
||||
match: ownProps.match,
|
||||
};
|
||||
};
|
||||
|
||||
export const ConnectedPokemonApp = connect(mapStateToProps, mapDispatchToProps, mergeProps)(PokemonApp);
|
||||
export const ConnectedPokemonApp = withRouter(connect(mapStateToProps)(PokemonApp));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import { RouteComponentProps, withRouter } from 'react-router-dom';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
@ -30,7 +30,6 @@ import * as PVPogoProtos from 'common/models/PVPogoProtos';
|
||||
|
||||
import * as styles from 'app/styles/PokemonApp.scss';
|
||||
|
||||
// TODO: better way to expose IRouterProps than just passing them in???
|
||||
interface IPokemonExplorerProps extends IRouterProps {
|
||||
isOverlaid : boolean;
|
||||
attackTypeEffectiveness : AttackTypeEffectiveness;
|
||||
@ -327,10 +326,7 @@ const mergeProps = (state : IPokemonExplorerStore, dispatchProps : IPokemonExplo
|
||||
...state,
|
||||
...dispatchProps,
|
||||
...ownProps,
|
||||
history: ownProps.history,
|
||||
location: ownProps.location,
|
||||
match: ownProps.match,
|
||||
};
|
||||
};
|
||||
|
||||
export const ConnectedPokemonExplorer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(PokemonExplorer);
|
||||
export const ConnectedPokemonExplorer = withRouter(connect(mapStateToProps, mapDispatchToProps, mergeProps)(PokemonExplorer));
|
||||
|
||||
@ -39,11 +39,7 @@ const store = Redux.createStore(
|
||||
const renderRoutePokemonApp = (props : IRouterProps) => {
|
||||
routePokemonApp(props, store.dispatch);
|
||||
return (
|
||||
<ConnectedPokemonApp
|
||||
history={ props.history }
|
||||
location={ props.location }
|
||||
match={ props.match }
|
||||
/>
|
||||
<ConnectedPokemonApp />
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user