Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Cannot read property 'type' of undefined #480

Closed
gCardinal opened this issue Nov 3, 2016 · 3 comments
Closed

Cannot read property 'type' of undefined #480

gCardinal opened this issue Nov 3, 2016 · 3 comments

Comments

@gCardinal
Copy link

I'm using react-router v3.0.0 and react-router-redux version 4.0.6 (they were both installed with npm with no version specified).

I read the issue #182, but this is not the problem I'm hitting at all. I get this error message every time I use a method from browserHistory to navigate my app (push, goBack, etc.).

Here's how things are configured (there's a few extra things, but I think it's safe to ignore those?):

// index.tsx
import 'polyfills'

import * as React from 'react'

import {render} from 'react-dom'
import {browserHistory} from 'react-router'
import {syncHistoryWithStore} from 'react-router-redux'

import App from 'App'

const createStore = require('redux/store/createStore') as any
const store = createStore.default(browserHistory)
const history = syncHistoryWithStore(browserHistory, store)

render(
    <App store={store} history={history}/>,
    document.getElementById('root')
)
// createStore.ts
import * as createLogger from 'redux-logger'

import {createStore, applyMiddleware, Middleware, compose, StoreEnhancer} from 'redux'
import {routerMiddleware} from 'react-router-redux'
import {composeWithDevTools} from 'redux-devtools-extension'
import {autoRehydrate} from 'redux-persist'

import thunk from 'redux-thunk'
import rootReducer from 'redux/reducers/RootReducer'

export default function (history?: any) {
    return createStore(
        rootReducer,
        null,
        compose(
            composeWithDevTools(
                applyMiddleware(
                    thunk,
                    routerMiddleware(history) as Middleware,
                    createLogger()
                )
            ),
            autoRehydrate()
        ) as StoreEnhancer
    )
}

And then, anywhere I use browserHistory, I'll get the error.

I've been having this problem for a while, but ignored it since it didn't break anything and I thought it was just my configuration that caused that problem. Reading the documentation here and looking at the examples though, I'm not sure of what I'm doing wrong. I'm sure it's something simple, but considering I seem to be configuring everything fine, I'm unsure of what could cause this.

I realize the problem is browserHistory is not dispatching actions the way Redux expects them, but then the documentation does suggest using browserHistory and the examples confirm this.

Is this a bug or am I doing something wrong?

@timdorr
Copy link
Member

timdorr commented Nov 3, 2016

We don't support RR 3 (and history 3 by proxy) at the moment. There is a PR to fix that that I need to release soon: #476

@timdorr
Copy link
Member

timdorr commented Nov 3, 2016

4.0.7 is out to fix this.

@timdorr timdorr closed this as completed Nov 3, 2016
@gCardinal
Copy link
Author

Wow, thanks a lot. I really didn't expect this to be resolved so quickly.

Again, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants