Skip to content

Commit

Permalink
fix: react-redux 6.0.0 new way of passing context (#113)
Browse files Browse the repository at this point in the history
* Fix react-redux 6.0.0 new way of passing context

* Remove unused Store

* Remove unused dispatch in type props NavLink

* Rebase from master
  • Loading branch information
GuillaumeCisco authored and ScriptedAlchemy committed Dec 29, 2018
1 parent 5a3f2bb commit d7e104f
Show file tree
Hide file tree
Showing 3 changed files with 1,868 additions and 2,655 deletions.
51 changes: 22 additions & 29 deletions src/Link.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @flow

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import type { Store } from 'redux'
import type { Connector } from 'react-redux'
import { selectLocationState } from 'redux-first-router'

Expand All @@ -29,34 +27,28 @@ type OwnProps = {
}

type Props = {
dispatch: Function // eslint-disable-line flowtype/no-weak-types
dispatch: Function, // eslint-disable-line flowtype/no-weak-types
routesMap: object
} & OwnProps

type Context = {
store: Store<*, *>
}

export const Link = (
{
to,
href,
location,
redirect,
replace,
tagName = 'a',
children,
onPress,
onClick,
down = false,
shouldDispatch = true,
target,
dispatch,
...props
}: Props
) => {
export const Link = ({
to,
href,
redirect,
replace,
tagName = 'a',
children,
onPress,
onClick,
down = false,
shouldDispatch = true,
target,
dispatch,
routesMap,
...props
}: Props) => {
to = href || to // href is deprecated and will be removed in next major version

const { routesMap } = location
const url = toUrl(to, routesMap)
const handler = handlePress.bind(
null,
Expand Down Expand Up @@ -97,9 +89,10 @@ export const Link = (
)
}

const mapState = state => ({ location: selectLocationState(state) })
const mapProps = dispatch => ({ dispatch })
const connector: Connector<OwnProps, Props> = connect(mapState, mapProps)
const mapState = state => ({
routesMap: selectLocationState(state).routesMap
})
const connector: Connector<OwnProps, Props> = connect(mapState)

// $FlowIgnore
export default connector(Link)
36 changes: 16 additions & 20 deletions src/NavLink.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @flow

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import type { Store } from 'redux'
import type { Connector } from 'react-redux'
import matchPath from 'rudy-match-path'
import { selectLocationState, getOptions } from 'redux-first-router'
Expand Down Expand Up @@ -36,25 +34,23 @@ type OwnProps = {
}

type Props = {
dispatch: Function
location: any
} & OwnProps

const NavLink = (
{
to,
href,
location,
className,
style,
activeClassName = 'active',
activeStyle,
ariaCurrent = 'true',
exact,
strict,
isActive,
...props
}: Props
) => {
const NavLink = ({
to,
href,
location,
className,
style,
activeClassName = 'active',
activeStyle,
ariaCurrent = 'true',
exact,
strict,
isActive,
...props
}: Props) => {
to = href || to

const options = getOptions()
Expand Down Expand Up @@ -82,7 +78,7 @@ const NavLink = (
className={combinedClassName}
style={combinedStyle}
aria-current={active && ariaCurrent}
location={location}
routesMap={location.routesMap}
{...props}
/>
)
Expand Down
Loading

0 comments on commit d7e104f

Please sign in to comment.