簡體   English   中英

“原始”參數的類型必須為 Function

[英]The “original” argument must be of type Function

我是 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',
  },
});

不要使用 require 在組件中導入客戶端,而是在文件頂部嘗試常規導入:

// Remove this line
const { Client } = require("cassandra-driver");

// and import at the top of the file =>

import React from 'react';
import { ... } from 'react-native';
import { Client } from 'cassandra-driver';

編輯:看起來 Cassandra 驅動程序是一個在后端與節點一起使用的工具,所以這個插件可能在 React-Native 中不起作用。 所以你必須在 node 中設置一個后端,然后從那里獲取 ReactNaive 中的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM