Reactotron: Redux Reactotron.createStore

Created on 10 Jul 2018  路  18Comments  路  Source: infinitered/reactotron

I've been looking through a lot of the issues associated with this and haven't been able to resolve my error. I'm getting the classic undefined is not a function (evaluating '_ReactotronConfig2.default.createStore(reducer, initialState)').

This is my App.js

import Reactotron from './ReactotronConfig';
import React, { Component } from 'react';
//import { createStore } from 'redux'
import { Provider } from 'react-redux'
import Stack from './src/screens/Stack'

const initialState = {
  checked: false
}

reducer = (state = initialState, action) => {
  switch (action.type) {
    case 'CHECK':
      return {
        checked: true
      }
    case 'UNCHECK':
      return {
        checked: false
      }
    default:
      return state
  }
}

const store = Reactotron.createStore(reducer, initialState)

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <Stack />
      </Provider>
    )
  }
}

This is my ReactotronConfig.js

import { reactotronRedux } from 'reactotron-redux'
import Reactotron from 'reactotron-react-native'

Reactotron
  .configure()
  .useReactNative()
  .use(reactotronRedux())
  .connect()

I appreciate any pointers in the right direction for this.

Most helpful comment

Put import './ReactotronConfig' at the very top of the app file.

All 18 comments

import Reactotron from './ReactotronConfig';
import React, { Component } from 'react';
//import { createStore } from 'redux'
import { Provider } from 'react-redux'
import Stack from './src/screens/Stack'

function createZStore() {
  const initialState = {
    checked: false
  }

  reducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHECK':
        return {
          checked: true
        }
      case 'UNCHECK':
        return {
          checked: false
        }
      default:
        return state
    }
  }

  return Reactotron.createStore(reducer, initialState)
}

const store = createZStore()

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <Stack />
      </Provider>
    )
  }
}

Out of interest can you try that?

@rmevans9 Tried that, same result.

Doh - I read your code wrong. You are importing "Reactotron" like so:

import Reactotron from './ReactotronConfig'

but it seems you are not exporting anything from ReactotronConfig. So you either need to export the Reactotron object from there or import reactotron from reactotron-react-native again in your app file.

What would be the right way to export that object then?

With the way you are importing it:

export default Reactotron

However you can avoid doing that and just import reactotron directly from reactotron-react-native again somewhere else and it will have the right methods attached to it.

I just did

import { reactotronRedux } from 'reactotron-redux'
import Reactotron from 'reactotron-react-native'

export default Reactotron 
  .configure()
  .useReactNative()
  .use(reactotronRedux())
  .connect() 

And now I get this undefined is not a function (evaluating 'a(b.apply(undefined, arguments))')

You wouldn't want to export the result of the connect() call

Ok.
This is what I have now.

ReactotronConfig.js

import { reactotronRedux } from 'reactotron-redux'
import Reactotron from 'reactotron-react-native'

Reactotron 
  .configure()
  .useReactNative()
  .use(reactotronRedux())
  .connect() 

App.js

import Reactotron from 'reactotron-react-native'
import React, { Component } from 'react';
//import { createStore } from 'redux'
import { Provider } from 'react-redux'
import Stack from './src/screens/Stack'

function createZStore() {
  const initialState = {
    checked: false
  }

  reducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHECK':
        return {
          checked: true
        }
      case 'UNCHECK':
        return {
          checked: false
        }
      default:
        return state
    }
  }

  return Reactotron.createStore(reducer, initialState)
}

const store = createZStore()

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <Stack />
      </Provider>
    )
  }
}

And this is still giving an undefined is not a function, but it has a different evaluation: (evaluating '_reactotronReactNative2.default.createStore(reducer, initialState)')

Put import './ReactotronConfig' at the very top of the app file.

I updated my comment to clarify what files are which. I do have it at the top.

Sorry if I was not clear. Make sure to import the ReactotronConfig file from within the App file.

import './ReactotronConfig'; // <- Here I am!
import Reactotron from 'reactotron-react-native'
import React, { Component } from 'react';
//import { createStore } from 'redux'
import { Provider } from 'react-redux'
import Stack from './src/screens/Stack'

function createZStore() {
  const initialState = {
    checked: false
  }

  reducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHECK':
        return {
          checked: true
        }
      case 'UNCHECK':
        return {
          checked: false
        }
      default:
        return state
    }
  }

  return Reactotron.createStore(reducer, initialState)
}

const store = createZStore()

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <Stack />
      </Provider>
    )
  }
}

Ah, I understand.

Same error: undefined is not a function (evaluating 'a(b.apply(undefined, arguments))')

The stack trace is different though, if that is significant at all...

I've replicated this locally. Give me a bit and I will get back to you.

Sounds good. Thanks!

It turns out reactotron-redux does not like NOT having middleware applied. Simply updating to this fixes the issue:

import './ReactotronConfig';
import Reactotron from 'reactotron-react-native'
import React, { Component } from 'react';
import { Provider } from 'react-redux'
import { compose, applyMiddleware } from 'redux';
import { View, Text } from 'react-native';
import { createLogger } from 'redux-logger'
// import Stack from './src/screens/Stack'

const logger = createLogger()

function createZStore() {
  const initialState = {
    checked: false
  }

  reducer = (state = initialState, action) => {
    switch (action.type) {
      case 'CHECK':
        return {
          checked: true
        }
      case 'UNCHECK':
        return {
          checked: false
        }
      default:
        return state
    }
  }

  const middleware = applyMiddleware(logger);
  return Reactotron.createStore(reducer, initialState, compose(middleware))
}

const store = createZStore()

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <View><Text>I am here</Text></View>
      </Provider>
    )
  }
}

I am closing this in favor of #741 as it contains this issue and other changes that need to be done to reactotron-redux. I will hopefully have some time in the coming days to see if I can work out a way to fix this issue. Until then I suggest using the above workaround

Ok, I'm not getting any errors now, which is awesome, thanks!

I'm just not getting reactotron to respond now. I did adb reverse tcp:9090 tcp:9090 in the past with this same project and it worked. Any suggestions on getting it to connect correctly?

Oop, false alarm, got it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eyesonly88 picture Eyesonly88  路  4Comments

sylar picture sylar  路  4Comments

tolu360 picture tolu360  路  5Comments

itaied246 picture itaied246  路  4Comments

Ashoat picture Ashoat  路  4Comments