reactotron icon indicating copy to clipboard operation
reactotron copied to clipboard

Expo.io setup

Open ecerroni opened this issue 9 years ago • 31 comments

If anyone made Reactotron work with Expo/Exponent do you mind sharing here the full exponent setup?

If is it really working it would be useful for further reference to have it included in the readme

Thanks

ecerroni avatar Apr 28 '17 11:04 ecerroni

I'll add another demo project and some docs.

Thx for the suggestion.

I had tested it with 15.x.x of expo and reactotron 1.9.x with no issues. I remember looking around at their Expo object and seeing some interesting stuff in there that people might want to see, so I was considering an expo plugin, but it's lower priority as I'm not using it day-to-day.

skellock avatar Apr 28 '17 11:04 skellock

Thanks @skellock I am struggling connecting the 2 so that I was wondering what's wrong in my setup.

Looking forward to the new demo project.

ecerroni avatar Apr 28 '17 11:04 ecerroni

Oh ya? Hmm... lemme check real quick here to see if something went wonky with either library updating.

If you're using a device to connect you'll need to make sure it's on the same network. We don't have the ability to tunnel thru expo's own connection to it's packager (ngrok or otherwise).

I'd love for that to be a thing.

A zero-configuration setup of Reactotron would make me giddy.

skellock avatar Apr 28 '17 12:04 skellock

Yep, you're right. I'm using the expo tunnel. Actually that's the only way I used expo so far.

I also tried with genymotion and got no results either.

So are you suggesting to set on Expo to set Host to LAN and Protocol to 'http` and then set the IP in the config file?

Something similar to:

Reactotron
    .configure({host: `${EXPO_IP}`)
    .connect();

I'm going to give it a try.

EDIT: I forgot to ask about this:

Finally, we import this on startup in index.ios.js and index.android.js on line 1:

import './ReactotronConfig'

There is no index.android.js in Expo afaik

ecerroni avatar Apr 28 '17 13:04 ecerroni

I got it to work with CRNA (Expo should be similar):

  • Get host of the packager
// host.js
import { NativeModules } from 'react-native';
import url from 'url';

const { hostname } = url.parse(NativeModules.SourceCode.scriptURL);

export default hostname
  • Configure reactotron:
// reactotron.js
import Reactotron from 'reactotron-react-native'

import host from './host'

Reactotron.configure({ host }).useReactNative().connect();
  • Init reactotron in dev:
// App.js
if (__DEV__) {
  require('./helpers/reactotron');

  const Reactotron = require('reactotron-react-native').default;
  Reactotron.log('Hello world');
}

const App = () => {
  // ...
}

export default App

inyono avatar Apr 29 '17 16:04 inyono

thank you!

skellock avatar Apr 29 '17 16:04 skellock

@ecerroni Where you able to make it work?

serranoarevalo avatar Jul 11 '17 09:07 serranoarevalo

@serranoarevalo Unfortunately not. Give it a second try after above comments with no success.

ecerroni avatar Jul 11 '17 13:07 ecerroni

Where are y'all getting stuck?

I just tried with Expo 18 again and it seems ok. Here's what I did:

  • Setup a new project with Expo 18.
  • setup my URL to exp://localhost:19000
  • yarn add --dev reactotron-react-native
  • updated main.js to look like this
import Expo from 'expo'
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import Reactotron from 'reactotron-react-native'

Reactotron.configure().useReactNative()

class App extends React.Component {
  componentDidMount () {
    Reactotron.connect()
  }

  render () {
    return (
      <View style={styles.container}>
        <Text>Hello Reactotron!</Text>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center' }
})

Expo.registerRootComponent(App)

If this doesn't work for you lemme know.

skellock avatar Jul 11 '17 14:07 skellock

I just created https://github.com/skellock/reactotron-plus-expo if you're interested.

skellock avatar Jul 11 '17 14:07 skellock

@skellock Thank you man! I was doing the Reactotron.connect() on a separate file following the installation guide the Readme, did on the componentDidMount and worked.

serranoarevalo avatar Jul 11 '17 14:07 serranoarevalo

Me too had it on a separate file. That was the problem.

Thank you for putting the example together.

ecerroni avatar Jul 11 '17 14:07 ecerroni

Totally my fault. My docs aren't consistent. Haha.

skellock avatar Jul 11 '17 16:07 skellock

So this works for me (with a separate Reactotron config)

Expo 18 and iOS Simulator - out of the box Expo 18 and remote device: Switch Expo-Cog setting "Host" to "LAN" and use @inyono 's great snippets above to set the host address; Expo/Reactotron/remote device on the sam LAN.

alexhafner avatar Jul 13 '17 23:07 alexhafner

Though the issue is closed, but after hours of debugging, I got it working on expo 24 via this configuration:

Reactotron
    .configure({lan: 'exp://localhost:19000'})  
    .useReactNative()
    .use(reduxPlugin())
    .connect();


eashish93 avatar Jan 04 '18 20:01 eashish93

@inyono solution works like a champ 💃

yordis avatar Jan 09 '18 09:01 yordis

I've hit a brick wall trying to get Reactotron up and running with Expo 25 and iOS Simulator... have tried all of the suggested url/config variations as well as the suggested snippets, alas Reactotron just doesn't connect :(

Can anyone confirm it working with the current release (expo 25 + reactotron 1.15.0 + reactotron-react-native 2.0.0-alpha.1)?

EDIT: Just downgraded to 1.14.0 and works as expected!

GfxKai avatar Feb 19 '18 03:02 GfxKai

+1

ecavalcanti avatar Feb 19 '18 03:02 ecavalcanti

It works out of the box for me using @inyono's setup.

Expo 25 + reactotron 2.0.0 alpha + reactotron-react-native 2.0.0 alpha.

@GfxKai why are you trying to use the standalone 1.15 app with reactotron-react-native 2.0.0 alpha? Use the 2.0.0 alpha standalone app. You need to ensure the standalone app you're using and rn package match.

kylegillen avatar Feb 19 '18 19:02 kylegillen

Let me share what I did, it is what @inyono suggested but I am also doing some fancy things around reactotron itself.

I am thinking on creating a library for these stuff but until then, here is my solution

// ./src/utils/reactotron.js

import url from "url"; // npm install url or yarn add url
import { NativeModules } from "react-native";
import Reactotron from "reactotron-react-native";
import { reactotronRedux } from "reactotron-redux";
import sagaPlugin from "reactotron-redux-saga";

const noop = () => {};

const configure = (appName, tron) => {
  const { hostname } = url.parse(NativeModules.SourceCode.scriptURL);

  tron
    .configure({ name: appName, host: hostname })
    .useReactNative()
    .use(reactotronRedux())
    .use(sagaPlugin())
    .connect();

  tron.clear();
};

export const setupReactotron = (appName, enabled = false) => {
  if (enabled) {
    configure(appName, Reactotron);
  }

  return {
    tron: Reactotron,
    withReactotron(withCallback, withoutCallback = noop) {
      // there is a reason why I am doing this, short answer, development vs production code
      return enabled ? withCallback(this.tron) : withoutCallback();
    }
  };
};

So far this util file will allow me to create some object that exposes withReactotron function.

How to use the util class

// file: ./src/reactotron.js 

import { setupReactotron } from "./utils/reactotron";
// just load whatever config file you have in your project, or maybe not.
import Config from "./config";

/*
Notice that I am using Config.useReactotron , this will allow me to call
withReactotron without worry about the environment I am running on so my code
do not suffer from if statements.

You could replace Config.useReactotron with !!__DEV__ if you want but I prefer
to use some config file.
*/
const reactotron = setupReactotron("Name of your App", Config.useReactotron);

export default reactotron;

How to use your reactotron instance

From now one, use your ./src/reactotron.js for do logging and stuff.

import Reactotron from "./reactotron"; // whatever path to YOUR reactotron file

Reactotron.withReactotron(tron => {
    // notice that I am using tron that is passed to this function.
   // because the withReactotron will never run if you disable reactotron
   // you do not need to worry about this function scope.
    tron.display({
      name: "PURGE",
      preview: "Reducer Version Change Detected",
      important: true,
      value: {
        "Old Version:": localVersion,
        "New Version:": reducerVersion
      }
    });
    // or do whatever else you want with tron instance
  });

I hope you find this useful, I like that I do not have to add if conditions everywhere in my code, it is a little more work but it pay off at the end of the day.

@skellock to be honest, I would love to see this approach of using Reactotron (meaning, withReactotron function) in the library itself. I am not a big fan of adding if statements everywhere for a code that will be no used on production. This way it is easier to remove code on build time as well, the AST will give you the full block that depends of the reactotron so you could remove it from the final AST.

yordis avatar Feb 19 '18 20:02 yordis