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:
},
name: {
alignSelf: 'center',
fontSize: ,
marginTop: ,
marginBottom: ,
color: 'white'
},
handle: {
alignSelf: 'center',
fontSize: ,
color: 'white'
},
image: {
height: ,
width: ,
borderRadius: ,
marginTop: ,
alignSelf: 'center'
}
}); class Badge extends React.Component {
render(){
return (
<View>
<Image style={styles.image} source={{uri: this.props.userInfo.avatar_url}}></Image>
<Text style={styles.name}> {this.props.userInfo.name} </Text>
<Text style={styles.handle}> {this.props.userInfo.login} </Text>
</View>
)
}
} /**
* 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;

[React Native] Reusable components with required propType的更多相关文章

  1. WHAT IS THE DIFFERENCE BETWEEN REACT.JS AND REACT NATIVE?

    Amit Ashwini - 09 SEPTEMBER 2017 React.js was developed by Facebook to address its need for a dynami ...

  2. 📝 没 2 年 React Native 开发经验,你都遇不到这些坑

    如果你喜欢我的文章,希望点赞 收藏 评论 三连支持一下,谢谢你,这对我真的很重要! React Native 开发时,如果只是写些简单的页面,基本上按着官方文档 reactnative.dev就能写出 ...

  3. [React Native] Using the Image component and reusable styles

    Let's take a look at the basics of using React Native's Image component, as well as adding some reus ...

  4. React Native pod install报错 `Yoga (= 0.44.3.React)` required by `React/Core (0.44.3)`

    使用pod安装,可能会因为Podfile的路径指向错误或者没有路径指向因为报错. 报错截图如下: 这是因为在指定的路径没有寻找到相应的组件.此时就需要修改podfile文件中的路径,由于上方提示没有  ...

  5. React Native 初步

    [React Native 初步] 1.Create React Native App is the easiest way to start building a new React Native ...

  6. 3.React Native在Android中自己定义Component和Module

    React Native终于展示的UI全是Native的UI.将Native的信息封装成React方便的调用. 那么Native是怎样封装成React调用的?Native和React是怎样交互的? V ...

  7. Xamarin vs React Native vs Ionic vs NativeScript: Cross-platform Mobile Frameworks Comparison

    CONTENTS Reading time: 14 minutes Cross-platform mobile development has long been a viable alternati ...

  8. React Native纯干货总结

    随着项目也渐渐到了尾声,之前的项目是mobile开发,采用的是React Native.为即将要开始做RN项目或者已经做过的小伙伴可以参考借鉴,也顺便自己做一下之前项目的总结. 文章比较长,可以选择自 ...

  9. react native 入门实践

    上周末开始接触react native,版本为0.37,边学边看写了个demo,语法使用es6/7和jsx.准备分享一下这个过程.之前没有native开发和react的使用经验,不对之处烦请指出.希望 ...

随机推荐

  1. hibernate实体的几种状态:

    hibernate实体的几种状态: 实体的生命周期中,实体主要经过瞬时(Transient),托管(Attatched或Managed),游离(Detached)和销毁(Removed)四个状态. 瞬 ...

  2. 在Linux上运行C#

    众所周知,C#是Microsoft推出的.NET语言,只能在.NET平台上运行,例如Win 9x.ME.NT.2000.XP和Win CE之类的操作系统.但是,现在却有了一个叫做Mono的项目,它的目 ...

  3. C#字符串与char数组互转!

    字符串转换成Char数组string str="abcdefghijklmnopqretuvwxyz";char[] chars=str.ToCharArray(); char数组 ...

  4. [.NET WebAPI系列01] WebAPI 简单例子

    [源] 来自微软WebAPI官方视频,Introduction to the ASP.NET Web API --Uniform Interface -- Demo-Using convention ...

  5. Windbg源码调试

    Windbg提供比VS2008丰富很多的调试命令,尤其是调试多线程程序. 今天试着怎么使用源代码方式调试.为了说明调试命令,<C++标准库>一书里的例子做示范. // testcast.c ...

  6. WebDriver 运行模式下使用rc 代码

    selenium2 对之前的rc 代码提供了兼容性接口,如果你之前的code 都是用rc 写,而现在又想摆脱要每次启动server,你只需要 略做修改即可.代码如下: public class Tes ...

  7. 【译】 AWK教程指南

    前面的话: 这几天写了一个程序,在同一个目录里生成了很多文件,需要统计其中部分文件的总大小,发现经常用到的ls.du等命令都无济于事,我甚至都想到了最笨的方法,写一个脚本:mkdir一个新目录,把要统 ...

  8. 初识Ajax---简单的Ajax应用实例

    原文: http://www.ido321.com/347.html 从网页前端输入提示范围内的字符,然后显示从后台返回的结果 1: <html> 2: <head> 3: & ...

  9. 第四章:ARP 地址解析协议

    网络接口有一个硬件地址,48bit的值,在硬件层次上进行的数据帧交换必须有正确的接口地址.tcp/ip有自己的地址,32bit的IP地址. 但是知道主机的IP地址并不能让内核发送一帧数据给主机.内核( ...

  10. tRNAscan-SE

    tRNAscan-SE是一款可以在基因组上扫描tRNA的序列,也就是说你给定一组基因序列(fasta数据格式),可以用这个软件去预测这个序列是不是tRNA.具体的实现原理,我不搞生物,所以也就不太明白 ...