如何将 functions/files 导入 React 本机应用程序?
How do I import functions/files to a react native app?
我正在使用 Sendbird 构建一个使用 React Native 的聊天应用程序,但我似乎无法 运行。我知道该应用程序本身可以工作,因为我使用了 javascript 调试器并且我正在将我的信息解析到控制台,但我似乎无法让 sendbird.init 工作。我是否需要像使用 React 函数那样从 sendbird 导入方法?
以下截图供参考:
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: ''});
}
});
}
});
以及现在出现的关于映射的错误:
New error - tried everything listed here
添加
var sendbird = require('sendbird');
在文件的开头。查看此 repo 中的 react-native 示例以获取示例 https://github.com/smilefam/SendBird-JavaScript
现在SendBird SDK V3支持最新的React Native,没有任何问题。
请将您的SendBird SDK更新到V3,然后就可以了。
这是您可以查看的示例项目。
https://github.com/smilefam/SendBird-JavaScript
谢谢!
我正在使用 Sendbird 构建一个使用 React Native 的聊天应用程序,但我似乎无法 运行。我知道该应用程序本身可以工作,因为我使用了 javascript 调试器并且我正在将我的信息解析到控制台,但我似乎无法让 sendbird.init 工作。我是否需要像使用 React 函数那样从 sendbird 导入方法?
以下截图供参考:
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: ''});
}
});
}
});
以及现在出现的关于映射的错误: New error - tried everything listed here
添加
var sendbird = require('sendbird');
在文件的开头。查看此 repo 中的 react-native 示例以获取示例 https://github.com/smilefam/SendBird-JavaScript
现在SendBird SDK V3支持最新的React Native,没有任何问题。
请将您的SendBird SDK更新到V3,然后就可以了。
这是您可以查看的示例项目。
https://github.com/smilefam/SendBird-JavaScript
谢谢!