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'

  

React(JSX语法)-----JSX属性的更多相关文章

  1. React(JSX语法)-----JSX基本语法

    JSX------HTML tags vs React Components: 1.To render a html tag,just use lower-case tag names in JSX; ...

  2. React(JSX语法)----JSX拼写

    注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...

  3. 22-React JSX语法

    React JSX语法 JSX只是一个语法糖,每一个XML标签都会被JSX转换工具转换成纯Javascript代码,当然你想直接使用纯Javascript代码写也是可以的,只是利用JSX,组件的结构和 ...

  4. 1.2 JSX 语法

    官方文档 https://facebook.github.io/react/docs/jsx-in-depth.html JSX 语法听上去很讨厌,但当真正使用的时候会发现,JSX 的写法在组件的组合 ...

  5. 2.ReactJS基础(虚拟DOM,JSX语法)

    将脚手架(create-react-app)创建的todolist项目精简为hello world示例 即,删除自动生成的样式文件.logo.svt.App.test.js.serviceWorker ...

  6. React JSX语法说明

    原文:http://my.oschina.net/leogao0816/blog/379487 什么是JSX? 在用React写组件的时候,通常会用到JSX语法,粗看上去,像是在Javascript代 ...

  7. react.js 从零开始(三)JSX 语法及特点介绍

    什么是jsx? jsx = JavaScript + xml jsx 是一种 Ecmascript 的一种新标准. jsx 是一种 带有结构性的语法. jsx 的特点: 1.类xml语法易于理解. 2 ...

  8. 【JAVASCRIPT】React学习-JSX 语法

    摘要 react 学习包括几个部分: 文本渲染 JSX 语法 组件化思想 数据流 JSX 语法 1. 定义 JSX 是javascript + xml 的合集,我们可以将javascript 与 ht ...

  9. React的JSX语法及组件

    最近一个同事很急没有做任何交接就请了陪产假,然后我来维护.说实在的我一开始是一脸懵逼的.因为MV*项目里用的最多的还是Vue:React听说也了解过,但毕竟不熟... 不过不管如何这也是工作:同事也恭 ...

随机推荐

  1. 转-深入理解VMware虚拟网络

    原文出处:http://wangchunhai.blog.51cto.com/225186/381225 VMware Workstation是一款非常不错的虚拟机软件,许多爱好者用VMware Wo ...

  2. iOS沙盒处理

    沙盒文件 每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,ios系统不允许访问其他应用的应用沙盒.在ios8中已经开放访问. 应用沙盒一般包括以下几个文件目录:应 ...

  3. C# winform TreeView中关于checkbox选择的完美类

    public static class TreeViewCheck { /// <summary> /// 系列节点 Checked 属性控制 /// </summary> / ...

  4. 5.String

    一.古罗马皇帝凯撒在打仗时曾经使用过一种方法加密军事情报.请编写一个程序,使用上述算法加密或解密用户输入的英文字串. 设计思想:先提示用户进行的操作是加密还是解密,用户输入一个字符串,加密时将前23个 ...

  5. php 字符串转数组

    $str = "你好吗"; function str($str) {     $length = mb_strlen($str);     for ($i=0; $i<$le ...

  6. C/C++技术常用网站

    软件下载网站[visual studio 2005编译器] http://www.xdowns.com/ debug调试大牛 http://blogs.msdn.com/oldnewthing/ ht ...

  7. logsatsh input 插件之 collectd

    logsatsh input 插件之 collectd 标签(空格分隔): logstash 作用:用于监控内存,cpu,磁盘I等信息 未完待续,时间未定. 参考: logstash 官网 elast ...

  8. ORACLE各种小指令

    清空表中所有记录truncate table et_xxxxxx 删除一条数据 DELETE FROM zhubajie_member.mb_web_login WHERE nickname='m_3 ...

  9. docker 源码分析 六(基于1.8.2版本),Docker run启动过程

    上一篇大致了解了docker 容器的创建过程,其实主要还是从文件系统的视角分析了创建一个容器时需要得建立 RootFS,建立volumes等步骤:本章来分析一下建立好一个容器后,将这个容器运行起来的过 ...

  10. jdk 编译器 对final字段的处理

    class FinalTest{     void a(){         final int i=10;         int j=10;     } }            stack=2, ...