【发布时间】:2021-06-18 16:06:09
【问题描述】:
我是 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',
},
});
【问题讨论】:
标签: javascript node.js react-native datastax datastax-java-driver