Meteor-like methods for React Native. Currently in v1.0.0-beta1 ! For old docs, see v0.6.2 documentation (classic ddp interface).
The purpose of this library is :
- to set up and maintain a ddp connection with a ddp server, freeing the developer from having to do it on their own.
- be fully compatible with react-native and help react-native developers.
- Use the EXACT SAME METHODS as Meteor documentation used with React.
npm i --save react-native-meteor
!! See detailed installation guide
import { View, Text, Component } from 'react-native';
import Meteor, { MeteorMixin } from 'react-native-meteor';
import reactMixin from 'react-mixin';
/*
* Uses decorators (see detailed installation to activate it)
* Or use :
class Todos extends Component {
...
}
reactMixin(Todos.prototype, MeteorMixin);
export default Todos;
*/
@reactMixin.decorate(MeteorMixin)
export default class App extends Component {
componentWillMount() {
const url = 'http://192.168.X.X:3000/websocket';
Meteor.connect(url);
}
startMeteorSubscriptions() {
Meteor.subscribe('todos');
}
getMeteorData() {
return {
todos: Meteor.collection('todos').find()
};
}
render() {
const { todos } = this.data;
{todos.map(todo=>{
return (
<View key={todo._id}>
<Text>{todo.title}</Text>
</View>
)
})}
}
}
Subscribe to subscriptions when component is mounted. It automatically unsubscribes if the component is unmounted.
Inside getMeteorData, you can access any Meteor reactive data source, that means :
- Meteor.collection(collectionName)
- Meteor.user()
- Meteor.userId()
- Meteor.status()
- Meteor.loggingIn()
Connect to a ddp server. You have to this only once in your app.
url
string required