ios - 无法读取未定义的属性 'string' 试图通过 react-native-create-bridge 理解 React Native Native 模块

标签 ios react-native react-native-native-module

我目前正在尝试做 Ios 版本的 this教程。
本教程简要介绍了通过 react-native-create-bridge 在 react-native 中使用原生模块

我应该会在文本下方看到一个简单的蓝色框。但是,我收到错误消息“无法准备好未定义的属性‘字符串’”。 enter image description here检查有问题的行并删除 .string 部分后。但是,页面现在呈现时没有预期的蓝色框。

这就是 ThirdSquareNativeView.js 的样子

//  Created by react-native-create-bridge

import React, { Component } from 'react'
import { requireNativeComponent } from 'react-native'

const ThirdSquare = requireNativeComponent('ThirdSquare', ThirdSquareView)

export default class ThirdSquareView extends Component {
  constructor() {
    super();
    console.log('this this working?');
  }
  render() {
    return <ThirdSquare {...this.props} />
  }
}

ThirdSquareView.propTypes = {
  exampleProp: React.PropTypes.string
}

最佳答案

您需要安装并导入 prop-types。它不再是 React 的一部分。

npm install prop-types --save

然后用作

import PropTypes from 'prop-types';

你的代码应该是这样的

ThirdSquareView.propTypes = {
  exampleProp: PropTypes.string
}

关于ios - 无法读取未定义的属性 'string' 试图通过 react-native-create-bridge 理解 React Native Native 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52399477/

相关文章:

android - 为 react-native native android 方法编写单元测试

ios - 尝试从HealthKit商店转换心率时发生异常

ios - 如何像邮件一样在 UITextView 中显示图像并使其居中

react-native - 重新排序 Flatlist 中的项目

react-native - Cookie 未正确存储在 ios 模拟器中

objective-c - 如何在 Objective-C 代码中重用 Swift 类型别名

javascript - 如何在 iOS 网络应用程序中获取实际屏幕高度

ios - 如何从 SwiftUI 列表和 Realm 中删除数据

node.js - 使用 Node 创建服务器并使用 React Native 获取端点

android - React Native Android 桥错误 : Method addObserver must be called on the main thread