在自定义视图中调用super()时,请确保传递组件构造函数传递的相同道具

Rah*_*ogi 3 javascript ecmascript-6 reactjs react-native

这是我生成的代码

警告:LoaderView(...):当调用super()时LoaderView,请确保传递组件构造函数传递的相同道具.

import * as React from "react";
import {ActivityIndicator, Text, View} from 'react-native'

    export class LoaderView extends React.Component {

        constructor(props) {
            super(props)
        }

        props = {
            title: "",
            loading: false
        }


        render() {
            if (this.props.loading) {
                return <View {...this.props} style={{flex: 1, justifyContent: 'center'}}>
                    <ActivityIndicator
                        size={"large"}
                        animating={true}/>

                    <Text
                        style={{textAlign: 'center', fontSize: 20, fontWeight: '500'}}>
                        {this.props.title}
                    </Text>
                </View>
            } else {
                return <View {...this.props} style={{flex: 1, justifyContent: 'center'}}>
                    <Text
                        style={{textAlign: 'center', fontSize: 20, fontWeight: '500'}}>
                        {this.props.title}
                    </Text>
                </View>
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

如何在上面的代码中解决此警告?

yan*_*029 10

使用defaultProps而不是props

static defaultProps = {
    title: "",
    loading: false
}
Run Code Online (Sandbox Code Playgroud)