我目前正在尝试做 Ios 版本的 this教程。
本教程简要介绍了通过 react-native-create-bridge 在 react-native 中使用原生模块
我应该会在文本下方看到一个简单的蓝色框。但是,我收到错误消息“无法准备好未定义的属性‘字符串’”。 检查有问题的行并删除 .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/