【问题标题】:Cannot read property 'oneOfType' of undefined无法读取未定义的属性“oneOfType”
【发布时间】:2018-06-28 04:59:16
【问题描述】:

我是原生反应的新手。我想使用'react-native-camera'。我创建了一个新项目,正确安装了包(我知道是因为我已经做了三次以确保我没有做错任何事情),它显示了这个错误**无法读取未定义的属性 'oneOfType' ** 和它在这个包'react-native-camera'的index.js中。我找不到任何解决方案。我已经尝试过更改 gradle 版本,gradle 包装器属性,但这个问题与 gradle 无关。这是我的 App.js 中的代码。我知道代码不会产生这个错误,但我是 react-native 的新手,所以我可能遗漏了一些东西。 任何建议将不胜感激

 import React, {Component} from 'react';
   import {
   Text,
   View,
  StyleSheet

 } from 'react-native';

 import Camera from 'react-native-camera';

 export default class BarcodeScan extends Component {

  constructor(props) {
    super(props);
    this.state = {
        qrcode: ''
    }
}

 onBarCodeRead = (e) => this.setState({qrcode: e.data});

 render () {
    return (
        <View  style={styles.container}>
            <Camera
                style={styles.preview}
                onBarCodeRead={this.onBarCodeRead}
                ref={cam => this.camera = cam}
                aspect={Camera.constants.Aspect.fill}
                >
                    <Text style={{
                        backgroundColor: 'white'
                    }}>{this.state.qrcode}</Text>
                </Camera>
          </View>
        )
    }

}

  const styles = StyleSheet.create({
  container: {
   flex: 1,
   flexDirection: 'row',
  },
   preview: {
   flex: 1,
   justifyContent: 'flex-end',
   alignItems: 'center'
  }
  });

【问题讨论】:

  • 请问您使用的是什么“react”和“react-native-camera”版本?
  • 由于您使用过 RCTCamera,请注意,从 1.0.0 开始,RCCTamera 已被弃用,但如果您想使用它,请使用此文档链接 github.com/react-native-community/react-native-camera/blob/…。您是否根据该链接进行了更改?请确认。
  • 显示你的 package.json 文件。

标签: react-native react-native-camera


【解决方案1】:

感谢这个人,https://github.com/dwicao/react-native-panel/issues/4
我能够通过替换包'react-native-camera'的index.js中的以下内容来解决这个问题。

替换

  import React, { Component, PropTypes } from 'react';

与

 import React, { Component } from 'react';
 import PropTypes from 'prop-types';

【讨论】:

    【解决方案2】:

    如果有人通过搜索标题(我做过)找到了这个帖子,我会添加我的经验。有时在 TSX 中,导入会变得有点奇怪。对我有用的是使用这个导入:

    import * as PropTypes from 'prop-types'

    我也需要对 React 本身做同样的事情,否则它也不起作用:

    import * as React from 'react'

    到目前为止,这是我需要为其执行此操作的仅有的两个导入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2020-10-30
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多