简体   繁体   English

无法读取 null 的属性“props” - React Native

[英]Cannot read property 'props' of null - React Native

I had a mobile application that i published like 2 months ago.我有一个 2 个月前发布的移动应用程序。 I have to make some changes now.我现在必须做出一些改变。 Before doing that, i upgraded android studio, so my sdk also upgraded to 28. I had several issues because of that but i could found solutions.在此之前,我升级了 android studio,所以我的 sdk 也升级到了 28。因此我遇到了几个问题,但我找到了解决方案。

But now, when i running my app on emulator, i have an error on some events.但是现在,当我在模拟器上运行我的应用程序时,我在某些事件上遇到了错误。

TypeError: TypeError: Cannot read property 'props' of null

This error is located at:
    in PickerAndroid (at Picker.js:159)
    in Picker (at Picker.android.js:11)
    in PickerNB (at connectStyle.js:384)
    in Styled(PickerNB) (at HomeScreen.js:626)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at TouchableOpacity.js:256)
    in TouchableOpacity (at Item.js:383)
    in Item (at connectStyle.js:384)
    in Styled(Item) (at HomeScreen.js:624)
    in RCTView (at View.js:45)
    in View (at ScrollView.js:852)
    in RCTScrollView (at ScrollView.js:977)
    in ScrollView (at HomeScreen.js:623)
    in RCTView (at View.js:45)
    in View (at HomeScreen.js:622)
    in RCTView (at View.js:45)
    in View (at HomeScreen.js:620)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at createAnimatableComponent.js:571)
    in withAnimatable(View) (at src/index.js:455)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at Modal.js:230)
    in RCTView (at View.js:45)
    in View (at Modal.js:250)
    in RCTModalHostView (at Modal.js:238)
    in Modal (at src/index.js:468)
    in ReactNativeModal (at HomeScreen.js:619)
    in RCTView (at View.js:45)
    in View (at react-native-drawer/index.js:579)
    in RCTView (at View.js:45)
    in View (at react-native-drawer/index.js:566)
    in Drawer (at Drawer/index.js:10)
    in Drawer (at HomeScreen.js:614)
    in HomeScreen (at navigationStore.js:448)
    in Wrapped (at SceneView.js:9)
    in SceneView (at StackViewLayout.js:478)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:477)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:476)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at screens.native.js:59)
    in Screen (at StackViewCard.js:42)
    in Card (at createPointerEventsContainer.js:26)
    in Container (at StackViewLayout.js:507)
    in RCTView (at View.js:45)
    in View (at screens.native.js:83)
    in ScreenContainer (at StackViewLayout.js:401)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:400)
    in StackViewLayout (at withOrientation.js:30)
    in withOrientation (at StackView.js:49)
    in RCTView (at View.js:45)
    in View (at Transitioner.js:141)
    in Transitioner (at StackView.js:19)
    in StackView (at createNavigator.js:57)
    in Navigator (at createKeyboardAwareNavigator.js:11)
    in KeyboardAwareNavigator (at createNavigationContainer.js:376)
    in NavigationContainer (at Router.js:97)
    in App (at Router.js:122)
    in Router (at App.js:59)
    in App (at renderApplication.js:34)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:33)

This error is located at:
    in NavigationContainer (at Router.js:97)
    in App (at Router.js:122)
    in Router (at App.js:59)
    in App (at renderApplication.js:34)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:33)
<unknown>
    PickerAndroid.android.js:87:16
mapSingleChildIntoContext
    react.development.js:1170:25
traverseAllChildrenImpl
    react.development.js:1043:4
traverseAllChildrenImpl
    react.development.js:1059:22
traverseAllChildren
    react.development.js:1114:9
mapIntoWithKeyPrefixInternal
    react.development.js:1192:2
Object.mapChildren [as map]
    react.development.js:1214:2
PickerAndroid._this._stateFromProps
    PickerAndroid.android.js:86:33
new
    PickerAndroid.android.js:69:23
<unknown>
    createClassProxy.js:98:23

I see this error when i use this component.当我使用这个组件时,我看到了这个错误。

    import React, { Component } from "react";
    import {
        View,
        Text,
        StyleSheet,
        TouchableOpacity,
TouchableHighlight
    } from "react-native";

    import Modal from "react-native-modal";

    import { Item, Label, Input, Textarea, Button } from 'native-base';

    import { HEADERBG } from './../Helper/config';

    import FontAwesome from 'react-native-vector-icons/FontAwesome';

    import ImagePicker from 'react-native-image-crop-picker';

    class NewPost extends Component {

        constructor(props){
            super(props);
            this.state = {
                category: null,
                messageText: null,
                isModalVisible: this.props.isVisible
            }

            this._toggleModal = this._toggleModal.bind(this);
        }

        _toggleModal(){
            this.setState({
                isModalVisible: !this.state.isModalVisible
            })
        }



        render() {
            return (
                <Modal style={{ flexDirection: 'column', justifyContent: 'flex-start' }} isVisible={this.props.isVisible}>
                    <View style={styles.container}>
                        <Text allowFontScaling={false} style={styles.headText}>Yeni Paylaşım Yap</Text>
                        <View style={styles.form}>
                            <Item style={styles.item} stackedLabel>
                                <Label style={styles.label}>Mesaj Kategorisi2</Label>
                                <Input onChangeText={(text) => this.setState({ email: text })} style={{padding: 10, borderWidth: 1/3, borderColor: 'gray', color: '#212121'}} blurOnSubmit={false} placeholder="E-Posta adresiniz" />
                            </Item>
                            <Item style={styles.item} stackedLabel>
                                <Label style={styles.label}>Mesajınız</Label>
                                <Text allowFontScaling={false}area rowSpan={5} bordered placeholder="Textarea" style={{ borderWidth: 1/4, color: '#212121', width: '100%' }} />
                            </Item>
                            <Item style={styles.item} stackedLabel>
                                <TouchableOpacity onPress={() => this.openPicker()} style={styles.imageButton}>
                                    <Text allowFontScaling={false} style={styles.imageText}>Görsel Seçin</Text>
                                </TouchableOpacity>
                            </Item>
                            <Button style={styles.sendButton} block>
                                <FontAwesome name="paper-plane" size={20} color="#fff" />
                                <Text allowFontScaling={false} style={{marginLeft: 5, fontSize: 16, color: '#fff'}}>Kapıyı Tıklat!</Text>
                            </Button>
                            <Button onPress={() => this._toggleModal()} style={{backgroundColor: '#E74C3C', marginVertical: 10}} block>
                                <FontAwesome name="times-circle" size={20} color="#fff" />
                                <Text allowFontScaling={false} style={{marginLeft: 5, fontSize: 16, color: '#fff'}}>Vazgeç!</Text>
                            </Button>
                        </View>
                    </View>
                </Modal>
            );
        }
    }

Your error is probably here : isModalVisible: this.props.isVisible你的错误可能在这里: isModalVisible: this.props.isVisible

You should write isModalVisible: false in the state if you do not pass anything from the props.如果你没有从 props 传递任何东西,你应该在 state 中写isModalVisible: false

Why there are 3 downvotes?为什么有3个downvotes? If someone's new we should try to understand their question and solve the issue如果某人是新来的,我们应该尝试了解他们的问题并解决问题

i think the issue is with react-native-image-crop-picker package!我认为问题在于 react-native-image-crop-picker 包! try to update it and reconfigure it again!尝试更新它并重新配置它!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM