Two packages with default export


#1

Hi,

I’m trying meteor with React native Using this plug-in : https://github.com/inProgress-team/react-native-meteor

and I am using https://reactnavigation.org/ for navigation.

it requires to do : export default StackNavigator({ … })

now I also want to use createContainer from the plugin, it also require :
export default createContainer(…)

obviously only one Default export is allowed, how am I supposed to managed this situation ?

Thanks.


#2

You have to think of StackNavigator and createContainer as returning React components. Once you realize this, you can realize that they are composable just like any other React components.


#3

Now that I’m at a proper code authoring device :slight_smile:

import React from 'react';
import { View, Text } from 'react-native';
import { createContainer } from 'react-native-meteor';
import { StackNavigator } from 'react-navigation';

const FirstScreen = ({things}) => (<View><Text>Screen #1, Should Display Things</Text></View>);
const SecondScreen = ({posts}) => (<View><Text>Screen #2, should display posts</Text></View>);

const FirstScreenContainer = createContainer(() => ({
    things: ThingsCollection.find(),
}), FirstScreen);

const SecondScreenContainer = createContainer(() => ({
    posts: PostsCollection.find(),
}), FirstScreen);

export default StackNavigator({
    FirstScreen: FirstScreenContainer,
    SecondScreen: SecondScreenContainer,
});

This is just an example and you’ll need to improvise to suit your app of course


#4

Thank you for your answer.

well may be I did not understand well, still I couldn’t manage to make createContainer work without “Export Default”.

I ended up separating createContainer with StackNavigator in two higher level components.

Since we’re at it, is there a best practice regarding using createContainer/withTracker with react ?

I mean we could use only one instance of withTracker in the whole app and spreading data to the children, or anytime we need it we can include withTracker in a file, or maybe regroup withTracker according to some logic for a group of react children (I guess this makes the most sense if we have a lot of data to push to react children) .