[React Native] Reusable components with required propType
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的更多相关文章
- 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 年 React Native 开发经验,你都遇不到这些坑
如果你喜欢我的文章,希望点赞 收藏 评论 三连支持一下,谢谢你,这对我真的很重要! React Native 开发时,如果只是写些简单的页面,基本上按着官方文档 reactnative.dev就能写出 ...
- [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 ...
- React Native pod install报错 `Yoga (= 0.44.3.React)` required by `React/Core (0.44.3)`
使用pod安装,可能会因为Podfile的路径指向错误或者没有路径指向因为报错. 报错截图如下: 这是因为在指定的路径没有寻找到相应的组件.此时就需要修改podfile文件中的路径,由于上方提示没有 ...
- React Native 初步
[React Native 初步] 1.Create React Native App is the easiest way to start building a new React Native ...
- 3.React Native在Android中自己定义Component和Module
React Native终于展示的UI全是Native的UI.将Native的信息封装成React方便的调用. 那么Native是怎样封装成React调用的?Native和React是怎样交互的? V ...
- 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 ...
- React Native纯干货总结
随着项目也渐渐到了尾声,之前的项目是mobile开发,采用的是React Native.为即将要开始做RN项目或者已经做过的小伙伴可以参考借鉴,也顺便自己做一下之前项目的总结. 文章比较长,可以选择自 ...
- react native 入门实践
上周末开始接触react native,版本为0.37,边学边看写了个demo,语法使用es6/7和jsx.准备分享一下这个过程.之前没有native开发和react的使用经验,不对之处烦请指出.希望 ...
随机推荐
- C# 分布式缓存服务器方案
- BZOJ3688: 折线统计
题解: 令f[i][j][0/1]表示前i个数有j段,最后一段是下降/上升的方案数 很容易列出状态转移方程(已按x轴排序) f[i][j][0]=sigma(f[k][j][0]+f[k][j-1][ ...
- ubuntuy用户切换和密码修改
修改当前用户的密码 $passwd 修改用户密码 $sudo passwd 用户名 切换到其他帐号(需要该用户的密码) $su 用户名 切换到root帐号 $sudo -s
- NGINX(七)分段下载
前言 nginx分段下载通过ngx_http_range_filter_module模块进行处理,关于HTTP分段下载过程,可以参考HTTP分段下载一文,主要分为一次请求一段和一次请求多段 涉及数据结 ...
- 【Python】不定期更新学习小问题整理
1 ctrl+D 退出python 2 from __future__ import division 小数除法 1/2 整除符号 // 比如4//2 3 为什么要写这个? reloa ...
- jquery日历datepicker的使用方法
jquery.ui.datepicker.js 用法: http://blog.csdn.net/zb0567/article/details/7906238 原文 http://blog.cs ...
- 【原】实验室签到PHP版本
表单 <html> <body> <h1>实验室自动签到测试</h1> <h2>输入学号和登录密码(建议自己改过密码后再来录入您的数据)&l ...
- Linux shell命令
一.删除监听指定端口的进程: lsof -ti: 80 | xargs kill -9 -t: 输出pid -i:查看指定端口占用情况 二.查看可执行文件动态链接库相关信息 ldd <可执行文件 ...
- Leetcode OJ : Compare Version Numbers Python solution
Total Accepted: 12400 Total Submissions: 83230 Compare two version numbers version1 and version2 ...
- Android Studio工程导入另一个工程作为lib
简单视频应用开发时,使用Vitamio作为视频解码库,官方建议直接以工程作为lib方便升级,将该工程导入到项目时不知道该怎么做,参考了下面的博客,这里存档标记一下. 参考:导入一个Android St ...