如何将函数/文件导入到react native应用程序中?

How do I import functions/files to a react native app?

本文关键字:native react 应用程序 导入 函数 文件      更新时间:2023-09-26

我正在使用Sendbird构建一个使用react native的聊天应用程序,但我似乎无法让它运行。我知道应用程序本身是有效的,因为我使用了javascript调试器,并且我正在将我的信息解析到控制台,但我似乎无法获得sendbird。Init来工作。我需要像你一样从sendbird导入方法来使用react函数吗?

以下是截图供参考:

Login Error: Sendbird not Defined

他们所指的那行,login.js:41是我调用sendbird.init

的地方

编辑:这是我的代码login.js(一切到样式表)

import React,  { Component } from 'react';
import {
    View,
    Text,
    StyleSheet,
    TextInput,
    TouchableHighlight
} from 'react-native';
var sendbird = require('sendbird');
module.exports = React.createClass({
    getInitialState: function() {
        return {
            username: ''
        };
    },
    render: function() {
        return (
            <View style={styles.container}>
                <View style={styles.loginContainer}>
                    <TextInput
                    style={styles.input}
                    value={this.state.username}
                    onChangeText={(text) => this.setState({username: text})}
                    placeholder={'Enter User Nickname'}
                    maxLength={12}
                    multiline={false}
                    />
                    <TouchableHighlight
                    style={styles.button}
                    underlayColor={'#328FE6'}
                    onPress={this.onPress}
                    >
                        <Text style={styles.label}>LOGIN</Text>
                    </TouchableHighlight>
                </View>
            </View>
        );
    },
    onPress: function() {
        sendbird.init({
            app_id: '879010F5-E064-4D1E-BD15-5956D4A47688',
            guest_id: this.state.username,
            user_name: this.state.username,
            image_url: "",
            access_token: "",
            successFunc: (data) => {
                console.log('success');
            },
            errorFunc: (status, error) => {
                this.setState({username: ''});
            }
        });
    }
});

和现在出现的关于映射的错误:新的错误-尝试了这里列出的所有

现在SendBird SDK V3支持最新的React Native,没有任何问题。

请将您的SendBird SDK更新到V3,然后应该就可以了。

这是一个示例项目,你可以看一下。

https://github.com/smilefam/SendBird-JavaScript

谢谢!

添加

var sendbird = require('sendbird');  

放在文件的开头。查看此repo中的react-native示例示例https://github.com/smilefam/SendBird-JavaScript