我似乎无法让createContainer使用React Native和Meteor数据。我目前使用的是react-native-meteor包和最新版本的Meteor/React Native。我已经查看了软件包的信息以及流星官方对createContainer的撰写。我想首先,我不太确定这个容器是如何工作的。它看起来像是包装了最后调用的组件,并在反应式数据发生变化时更新它?
我已经尝试了几种不同的方法,但下面是我目前正在使用的。我不确定是否调用了createContainer,因为我在控制台中没有从我的日志语句中看到任何东西。我也尝试过使用Meter.user()和Meteor.userId(),但没有成功。你知道我做错了什么吗?
'use strict';
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import { loginToSpotify } from './react-native-spotify-auth'
import Meteor, { createContainer } from 'react-native-meteor'
//import { testComponent } from './component'
//TODO: openURL bug on iOS9 causes iOS to confirm before redirect: http://stackoverflow.com/questions/32312009/how-to-avoid-wants-to-open-dialog-triggered-by-openurl-in-ios-9-0
//May also want to look into using Universal links
Meteor.connect('http://localhost:3000/websocket');//do this only once
class ReactNativeApp extends Component {
constructor(props) {
super(props);
this.state = {
access_token: null
};
}
componentDidMount() {
loginToSpotify();
}
render() {
const { todosReady } = this.props;
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<Text>
Hello {!todosReady && <Text>Not Ready</Text>}
</Text>
</View>
);
}
}
export default createContainer(params=>{
const handle = Meteor.subscribe('todos');
console.log('todos: ' + Meteor.collection('todos').find());
return {
todosReady: handle.ready()
}
}, ReactNativeApp);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
});
AppRegistry.registerComponent('ReactNativeApp', () => ReactNativeApp);发布于 2016-09-09 00:47:36
你能在控制台看到连接到应用程序的流星吗?您不应该再在Meteor.connect中使用http,而应该使用ws://localhost:3000/websocket
发布于 2017-04-08 14:13:40
有关更多信息,请访问此React Native Meteor Boilerplate。
https://stackoverflow.com/questions/37242113
复制相似问题