我是新的React Native,并试图连接数据库与我的程序。我得到这个错误,我不知道该如何尝试修复它...
TypeError: The "original" argument must be of type Function
Profil
src/jsoni/Profil.js:4
1 | import React from 'react';
2 | import { StyleSheet, SafeAreaView,TouchableOpacity,Text} from 'react-native';
3 |
> 4 | export default function Profil({navigation}) {
5 |
6 |
7 | const { Client } = require("cassandra-driver");
......而这个......
Unhandled Rejection (TypeError): Client is not a constructor
registerRootComponent
src/launch/registerRootComponent.web.tsx:14
11 | const RootComponent: React.FC<P> = props => <App {...props} />;
12 | AppRegistry.registerComponent('main', () => RootComponent);
13 | const rootTag = document.getElementById('root') ?? document.getElementById('main');
> 14 | AppRegistry.runApplication('main', { rootTag });
15 | }
16 |
我正在使用DataStax Astra数据库,下面是我尝试做的https://docs.datastax.com/en/astra/docs/connecting-to-your-database-with-the-datastax-nodejs-driver.html
这是我的密码...
import React from 'react';
import { StyleSheet, SafeAreaView,TouchableOpacity,Text} from 'react-native';
export default function Profil({navigation}) {
const { Client } = require("cassandra-driver");
async function run() {
const client = new Client({
cloud: {
secureConnectBundle: "../../secure-connect-test.zip",
},
credentials: {
username: "myusername",
password: "mypassword",
},
});
await client.connect();
// Execute a query
const rs = await client.execute("SELECT firstname FROM keyspace.table");
console.log(rs.rows);
await client.shutdown();
}
// Run the async function
run();
const press = () => {
navigation.navigate('Home');
}
return (
<TouchableOpacity onPress={press}>
<SafeAreaView>
<SafeAreaView style={styles.border}/>
<Text>Text here</Text>
</SafeAreaView>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
border: {
height: 50,
width:100,
backgroundColor:'#ff69ff',
},
});
1条答案
按热度按时间deikduxw1#
请尝试在文件顶部进行常规导入,而不要使用require将客户端导入组件中:
编辑:看起来Cassandra Driver是一个在节点后端使用的工具,所以这个插件可能在React-Native中不起作用。所以你必须在节点中设置一个后端,然后从那里获取ReactNaive中的结果。