Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to react-native@0.8.0 produces dispatch is not a function #10

Closed
felixakiragreen opened this issue Jul 27, 2015 · 2 comments
Closed

Comments

@felixakiragreen
Copy link

I was using react-native@0.8.0-rc with no issues, then I upgraded to the full release and now I'm getting this error: dispatch is not a function. (In ‘dispatch(actionCreator.apply(undefined, arguments))’, ‘dispatch’ is undefined)

When I downgrade back to react-native@0.8.0-rc, it works fine and goes away. I have no idea what changed. Maybe it's a react-native issue?

These are my containers... I can provide more if needed. Right now it's pretty basic, mostly just following the examples.

// App.js
import React, { Component } from 'react-native'
import { createStore, applyMiddleware, combineReducers } from 'redux'
import { Provider } from 'react-redux/native'
import thunk from 'redux-thunk'

import * as reducers from '../reducers'
import VetoApp from './VetoApp'

const createStoreWithMiddleware = applyMiddleware(thunk)(createStore)
const reducer = combineReducers(reducers)
const store = createStoreWithMiddleware(reducer)

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        {() => <VetoApp />}
      </Provider>
    )
  }
}
// VetoApp.js
import React, { Component } from 'react-native'
import { bindActionCreators } from 'redux'
import Main from '../components/Main'
import * as ViewActions from '../actions/view'
import { connect } from 'react-redux/native'

@connect(state => ({
  state: state.view
}))
export default class CounterApp extends Component {
  render() {
    const { state, dispatch } = this.props
    console.log(dispatch) // results in undefined
    return (
      <Main
        viewSettings={state}
        {...bindActionCreators(ViewActions, dispatch)}
      />
    )
  }
}

EDIT: now downgrading doesn't work. I reverted my app to the exact same state before and it doesn't work. dispatch is not a function. No idea what suddenly changed.

@felixakiragreen
Copy link
Author

Using the Connector component works:

'use strict'

import React, { Component } from 'react-native'
import { bindActionCreators } from 'redux'
import Main from '../components/Main'
import * as ViewActions from '../actions/view'
import { connect } from 'react-redux/native'
import { Connector } from 'react-redux/native'

// @connect(state => ({
//   state: state.view
// }))
// export default class CounterApp extends Component {
//   render() {
//     const { state, dispatch } = this.props
//     return (
//       <Main
//         viewSettings={state}
//         {...bindActionCreators(ViewActions, dispatch)}
//       />
//     )
//   }
// }

export default class CounterApp extends Component {
  render() {
    return (
      <Connector select={state => ({ state: state.view })}>
        {this.renderChild}
      </Connector>
    )
  }

  renderChild({ state, dispatch }) {
    return (
      <Main
        viewSettings={state}
        {...bindActionCreators(ViewActions, dispatch)}
      />
    )
  }
}

@felixakiragreen
Copy link
Author

It's a babel.js bug

babel/babel#2086

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

No branches or pull requests

1 participant