简体   繁体   English

在init()方法上引发错误的原因是什么?

[英]What's the reason for the error being thrown on init() method?

I used https://www.npmjs.com/package/react-native-dynamodb to implement DynamoDB access for my project. 我使用https://www.npmjs.com/package/react-native-dynamodb为我的项目实现DynamoDB访问。 I used the same exact code as that website. 我使用与该网站完全相同的代码。

The only thing is, I can't see how my .init() method is giving me: Unresolved function or method init() upon hovering over it (I'm using the WebStorm IDE by the way). 唯一的事情是,我看不到.init()方法如何给我:将鼠标悬停在它上面时, Unresolved function or method init() (我正在使用WebStorm IDE)。 I believe that's the reason why my app won't run. 我认为这就是我的应用无法运行的原因。 Below is the code as well as the error I'm getting in the simulator. 下面是代码以及我在模拟器中遇到的错误。

Error in iOS Simulator iOS模拟器错误

Here's my .js file: 这是我的.js文件:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { ScrollView, Text, View, Button } from 'react-native';
import { logout } from '../redux/actions/auth';
import DropdownMenu from 'react-native-dropdown-menu';
import Icon from './Icon';
import DynamoDB from 'react-native-dynamodb';

let dynamodb = DynamoDB.init({
    credentials: {
        AccessKeyId: 'Some key',
        SecretKey: 'Some key'
    }
    // region: 'us-east-1' - default, optional
    // version: '20120810' - default, optional
})

dynamodb.table('user_choice').PutItem(
    {
        name: 'Jack Sparrow',
        age: 30,
        captain: true
    },

    {
        ConditionExpression: "last_movie <> :movie",
        ExpressionAttributeValues: {
            ":movie": {"S": "Pirates of the Caribbean: On Stranger Tides"}
        }
    })
    .then((response) => console.log(response)) // AWS object response
    .catch((error) => {
        console.log(error)
    })

class Secured extends Component {
    render() {
        var data = [["Literacy Leaders"], ["Wrestling Camp"], ["Screenplay Writing"], ["Panetarium Workshop"]];

        return(
            <ScrollView style={{padding: 20}}>
                <Icon/>

                <Text style={{fontSize: 27}}>
                    {`Welcome ${this.props.username}`}
                </Text>

                <View style={{flex: 1}}>

                    <DropdownMenu style={{flex: 1}}
                                  bgColor={"purple"}  //the background color of the head, default is grey
                                  tintColor={"white"} //the text color of the head, default is white
                                  selectItemColor={"orange"} //the text color of the selected item, default is red
                                  data={data}
                                  maxHeight={410}  // the max height of the menu
                                  handler={(selection, row) => alert(data[selection][row])} >

                        <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}} >
                        </View>
                    </DropdownMenu>

                </View>

                <View style={{margin: 20}}/>

                <Button onPress={(e) => this.userLogout(e)} title="Logout"/>

            </ScrollView>
        );
    }
}

const mapStateToProps = (state, ownProps) => {
    return {
        username: state.auth.username
    };
}

const mapDispatchToProps = (dispatch) => {
    return {
        onLogout: () => { dispatch(logout()); }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Secured);

I checked the source code of react-native-dynamodb , seems DynamoDB is not exported as default but a named export. 我检查了react-native-dynamodb的源代码,似乎DynamoDB并非默认导出,而是命名导出。

Try import it like this: 尝试像这样导入它:

import { DynamoDB } from 'react-native-dynamodb';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何捕获XMLHttpRequest的onload方法中引发的错误 - How to catch an error thrown in XMLHttpRequest's onload method ModalInstanceCtrl出现此错误的最常见原因是什么? - What's the most common reason for ModalInstanceCtrl to give this error? 如何断言在 AWS Lambda 中使用 Jest 的模拟方法抛出的错误 - How to assert an error being thrown by mocked method using Jest in AWS Lambda React组件引发的错误,被错误的promise的catch块捕获 - An error thrown by a React component, being caught in an unrelated promise's catch block 错误未在异步函数内引发 - Error not being thrown inside async function 扩展init方法而无需递归,javascript - extending init method without being recursive, javascript React Native 中出现此错误的原因是什么? - What is the reason for this error in React Native? 出现以下错误的原因可能是什么 - What can be the reason for the following error ExtJS:init是模板方法,什么是模板方法? - ExtJS: init is a template method, what is a template method? 无法在实际页面之外的其他服务器上承载文本轨道的背后原因是什么,有没有办法消除这种限制? - What's a reason behind not being able to host text tracks on a separate server than the actual page and is there a way to remove that limitation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM