1. if you know all the propertities that you want to place on a component ahead of time,it is easy to use JSX:

var component = <Component foo={x} bar={y}/>

2. This is an anti-pattern (反面实例---错误的) because it means that we can't help you check the right propTypes until way later.This means that your propTypes errors end up with a cryptic stack trace.

var component = <Component/>;
component.props.foo = x; //bad
component.props.bar = y;//also bad

  the props should be considered immutable at this point(认为是不可改变的).Mutating the props object somewhere else could cause unexpected consequences so ideally it would be a frozen object at this point.

3.you can use a new feature of JSX called spread attributes:

var props = {};
props.foo = x;
props.bar = y;
var component = <Component {...props}>;

  the properties of the object that you pass in are copied onto the component's props.you can use this multiple times or combine it with other attributes.The specification order id important.Later attributes override previous ones;

var props = { foo: 'default' };
var component = <Component {...props} foo={'override'} />;
console.log(component.props.foo); // 'override'

  

最新文章

  1. Android SDK 在线更新镜像服务器资源
  2. Xamarin的不归路-安卓模拟器启动慢&amp;没有虚拟键盘
  3. 如何区分/dev/input/event
  4. PHP的版本选择 (转)
  5. Tigase数据库结构(1)
  6. locality
  7. Css3中的响应式布局的应用
  8. jQuery插件之artDialog
  9. POJ 2774 Long Long Message(后缀数组)
  10. Hack 语言学习/参考---1.3 Summary
  11. Objective-C日记-之KVC
  12. jQuery获取父级、兄弟节点的方法
  13. CodeMirror tab转空格
  14. nosql数据库:mongodb,redis,memcached,其优缺点和使用应用场景
  15. 检查浏览器是否已经启用Java支持功能
  16. indy10的idHttpServer发送流
  17. qt编程遇到的东西
  18. 标准的sql执行顺序
  19. Noip前的大抱佛脚----Noip真题复习
  20. 根据现有表操作基于active record的model

热门文章

  1. linux系统中查看系统位数(转载)
  2. CSS-position详解
  3. mac idea快捷键
  4. ubuntu安装谷歌输入法
  5. 关于linq to sql类线程同步问题
  6. css中文乱码与替换字符
  7. Disable the screen switching about VI
  8. Eclipse/JavaWeb (三)三大框架之Spring框架 持续更新中...
  9. 实时控制软件设计 第一次作业 Draw
  10. SQLServer将表数据导出为Insert语句