博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React Native] Reusable components with required propType
阅读量:5119 次
发布时间:2019-06-13

本文共 1440 字,大约阅读时间需要 4 分钟。

In this React Native lesson, we will be creating a reusable Badge component. The component will also make use of propTypes to validate that its required data is being passed in when it is used.

 

We are going to build Badge component which will just show the user image. This componet will be reused into Profile, Bio and Note component as well.

 

import React, {Component} from 'react';import {Text, View, StyleSheet, Image} from 'react-native';var styles = StyleSheet.create({    container: {        backgroundColor: '#48BBEC',        paddingBottom: 10    },    name: {        alignSelf: 'center',        fontSize: 21,        marginTop: 10,        marginBottom: 5,        color: 'white'    },    handle: {        alignSelf: 'center',        fontSize: 16,        color: 'white'    },    image: {        height: 125,        width: 125,        borderRadius: 65,        marginTop: 10,        alignSelf: 'center'    }});class Badge extends React.Component {    render(){        return (            
{
this.props.userInfo.name}
{
this.props.userInfo.login}
) }}/** * Make sure when when user the Badge component, the userInfo object is there * @type {
{userInfo: *}} */Badge.propTypes = { userInfo: React.PropTypes.object.isRequired};module.exports=Badge;

 

转载于:https://www.cnblogs.com/Answer1215/p/5713281.html

你可能感兴趣的文章
基于C#编程语言的Mysql常用操作
查看>>
s3c2440实验---定时器
查看>>
MyEclipse10安装SVN插件
查看>>
[转]: 视图和表的区别和联系
查看>>
Regular Experssion
查看>>
图论例题1——NOIP2015信息传递
查看>>
uCOS-II中的任务切换-图解多种任务调度时机与问题
查看>>
CocoaPods的安装和使用那些事(Xcode 7.2,iOS 9.2,Swift)
查看>>
Android 官方新手指导教程
查看>>
幸运转盘v1.0 【附视频】我的Android原创处女作,请支持!
查看>>
UseIIS
查看>>
集合体系
查看>>
vi命令提示:Terminal too wide
查看>>
引用 移植Linux到s3c2410上
查看>>
MySQL5.7开多实例指导
查看>>
[51nod] 1199 Money out of Thin Air #线段树+DFS序
查看>>
poj1201 查分约束系统
查看>>
Red and Black(poj-1979)
查看>>
分布式锁的思路以及实现分析
查看>>
腾讯元对象存储之文件删除
查看>>