【问题标题】:React Native & Meteor implementationReact Native 和 Meteor 实现
【发布时间】:2016-07-08 18:52:59
【问题描述】:

我正在开发一个带有流星后端的 react 本机应用程序。我知道要将这两者联系在一起,我必须使用节点包 ddp-client 来连接应用程序。 https://www.npmjs.com/package/ddp-client

但是解决此问题的最佳做法是什么。我应该:

  1. 定义 DDPClient 并在我保持连接的 index.ios.js 中连接并找到某种方法从主应用程序组件发出请求? (不过我不知道该怎么做,但这将是一个开始。)

  2. 是否只通过 dpp 在我需要的每个组件上连接并每次发出请求?

真的,任何真实的例子都会有所帮助。我在网上找到的大部分代码都是单页示例,其他的不多。或者只是朝着正确的方向推进。

附言该应用程序是一个市场。谢谢!

'use strict';
var React = require('react-native');
var {
  AppRegistry,
  NavigatorIOS,
  StyleSheet,
  StatusBarIOS,
} = React;

var DDPClient = require("ddp-client");

class AppWrapper extends React.Component{

  componentDidMount() {
    var ddpClient = new DDPClient({url: 'ws://localhost:3000/websocket'});

    ddpClient.connect(function(error, wasReconnect) {
      if (error) {
        console.log('DDP connection error!');
        return;
      }
      if (wasReconnect) {
         console.log('Reestablishment of a connection.');
       }
      console.log('connected!');
    });
  }

  render(){
    return(
      <NavigatorIOS
        barTintColor='black'
        titleTextColor='white'
        tintColor='white'
        style={styles.container}
        translucent={false}
        initialRoute={{
          backButtonTitle: ' ',
          component: Homeios,
          title: 'hombro',
        }}
      />
    )
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

AppRegistry.registerComponent('someApp', () => AppWrapper);

【问题讨论】:

    标签: ios meteor reactjs react-native


    【解决方案1】:

    您可以在您的 react native 应用程序中使用 react-native-meteor 包,这非常简单。 https://www.npmjs.com/package/react-native-meteor 查看此链接以获取文档,它有许多很棒的功能,包括可供使用的 Accounts 包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多