首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用createContainer将流星数据导入React Native时出现问题

使用createContainer将流星数据导入React Native时出现问题
EN

Stack Overflow用户
提问于 2016-05-16 02:28:36
回答 2查看 447关注 0票数 2

我似乎无法让createContainer使用React Native和Meteor数据。我目前使用的是react-native-meteor包和最新版本的Meteor/React Native。我已经查看了软件包的信息以及流星官方对createContainer的撰写。我想首先,我不太确定这个容器是如何工作的。它看起来像是包装了最后调用的组件,并在反应式数据发生变化时更新它?

我已经尝试了几种不同的方法,但下面是我目前正在使用的。我不确定是否调用了createContainer,因为我在控制台中没有从我的日志语句中看到任何东西。我也尝试过使用Meter.user()和Meteor.userId(),但没有成功。你知道我做错了什么吗?

代码语言:javascript
复制
'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);
EN

回答 2

Stack Overflow用户

发布于 2016-09-09 00:47:36

你能在控制台看到连接到应用程序的流星吗?您不应该再在Meteor.connect中使用http,而应该使用ws://localhost:3000/websocket

票数 0
EN

Stack Overflow用户

发布于 2017-04-08 14:13:40

  1. 请确保您的meteor应用程序正在运行。
  2. 使用本地机器的IP,不要使用本地主机。如果你使用手机作为模拟器,这是很好的。在路由器中连接两者并使用您的机器语言。

有关更多信息,请访问此React Native Meteor Boilerplate

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37242113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档