Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对象存在于道具中,但不会创建元素反应本机流错误_Javascript_Reactjs_React Native_Flowtype - Fatal编程技术网

Javascript 对象存在于道具中,但不会创建元素反应本机流错误

Javascript 对象存在于道具中,但不会创建元素反应本机流错误,javascript,reactjs,react-native,flowtype,Javascript,Reactjs,React Native,Flowtype,我一直在试图弄清楚为什么我的React原生项目中会出现流错误。我无法找到一个直截了当的答案,因此我感到困惑。该项目的工作,但我仍然有这个错误 无法创建TextInput元素,因为已触摸属性 对象类型[1]中缺少,但道具[2]中存在。[1] [2] 无法创建TextInput元素,因为缺少属性valid 在对象类型[1]中,但存在于道具[2]中。[1] [2] 这是在下面代码的第8行 // @flow import React from 'react'; import { TextInput, S

我一直在试图弄清楚为什么我的React原生项目中会出现流错误。我无法找到一个直截了当的答案,因此我感到困惑。该项目的工作,但我仍然有这个错误

无法创建
TextInput
元素,因为已触摸属性
对象类型[1]中缺少,但道具[2]中存在。[1] [2]

无法创建
TextInput
元素,因为缺少属性
valid
在对象类型[1]中,但存在于道具[2]中。[1] [2]

这是在下面代码的第8行

// @flow
import React from 'react';
import { TextInput, StyleSheet } from 'react-native';

type Props = { style: Object, valid?: bool, touched?: bool };

const defaultInput = (props: Props) => (
    <TextInput   <--- Error Points Here!!!
      underlineColorAndroid="transparent"
      {...props}
      style={[styles.input, props.style, !props.valid && props.touched ? styles.invalid : null]}

    />
);

const styles = StyleSheet.create({
    input: {
      width: "100%",
      borderWidth: 1,
      borderColor: "#eee",
      padding: 5,
      marginTop: 8,
      marginBottom: 8
    },
    invalid: {
      backgroundColor: '#f9c0c0',
      borderColor: 'red'
    }
  });

export default defaultInput;
/@flow
从“React”导入React;
从“react native”导入{TextInput,样式表};
类型Props={style:Object,valid?:bool,toucted?:bool};
const defaultInput=(props:props)=>(

在这里帮忙有点晚了,但我也遇到了这个问题,并开始寻找答案,所以希望这能帮助其他人

我可以通过使用功能组件中使用的道具来解决问题,如下所示:

type Props = {
   loading: boolean
};

export default function LoadingIndicator(props: Props) {

   // this is the key! Take out the props you've defined in your type above
   const { loading, ...other } = props;

   if (loading) {

      return (
         <View
            {...other}
            style={styles.loadingIndicator}>
            <ActivityIndicator animating size="large" />
         </View>
      );
   } else return null;
}
类型道具={
加载:布尔值
};
导出默认函数加载指示器(道具:道具){
//这是关键!拿出你在上面类型中定义的道具
常量{loading,…other}=props;
如果(装载){
返回(
);
}否则返回null;
}
确保将
…道具
更改为您命名的剩余道具,在本例中为
…其他


就是这样!错误会消失。

我怀疑这是因为您声明了
valid
toucted
是可选的。这不是问题所在。当它不是可选的时候,错误仍然会出现。当它不是可选的时候,我遇到了其他错误。我将它设置为可选的,因为我的一些类使用它时没有被触摸并且有效好的,
TextInput
的道具声明类型是什么?TextInput来自React原生框架。我不确定道具的类型,因为我使用类型道具来保存道具。