reactjs - React Native 我在这里做错了什么
问题描述
我正在尝试实现一个功能组件。我在下面做,但我收到关于道具的错误。有人可以帮助我。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
const TextField = () => {
return (
<Text> {this.props.title} </Text>
)
}
export default TextField;
// APP Component
import TextField from './Components/TextField'
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<TextField title= "Simple App"/>
</View>
);
}
}
解决方案
原因是this.props
未在功能组件中定义。他们接收道具作为参数。
改变你TextField
的接受论点props
和使用props.title
const TextField = (props) => {
return (
<Text> {props.title} </Text>
)
}
推荐阅读
- java - NullPointerException:尝试调用虚拟方法'void org.apache.cordova.CordovaPlugin.privateInitialize
- python - 合并年和周列以在 python 中创建日期时间和排序
- roku - 如何增加 Roku 的响应时间
- machine-learning - 当标注维度太大,想找另一种方式而不是one-hot编码时
- html - AMP Carousel 不能用于多个项目
- d3.js - D3条形图yaxis缩放问题,我不想要十进制/重复值
- android - 我正在尝试构建一个 Tinder 克隆,在其中我想过滤我在“刷卡”上显示的用户
- json - 如何管理 webhook 数据格式的标准化?
- android - 由于“多个 dex 文件定义”而导致的 Android Studio 3.5.2 项目构建问题
- git - Git Bash - 推送命令错误“CreateProcessW failed error:193”