2016-12-30 58 views
1
// modules/NavLink.js 
import React from 'react' 
import { Link } from 'react-router' 

export default React.createClass({ 
    render() {   
    //for example this.props={from: "home", to: "about"} 
    return <Link {...this.props} activeClassName="active"/> // ???what does the statement compile to es5? 
    } 
}) 

// modules/App.js 
import NavLink from './NavLink' 

// ... 

<li><NavLink to="/home">Home</NavLink></li> 

的quesion的JSX ES6对象传播经营者低于:在reactjs

<Link {...this.props} activeClassName="active"/>,这句话是什么编译为ES5,如果this.props = {到: “/家庭”,孩子们:“首页“}?

+0

你可以找到你自己:https://babeljs.io/repl/。 –

回答

2

Straight from the Babel homepage

React.createElement(Link, _extends({}, this.props, { activeClassName: "active" })); 

我省略了_extends填充工具,它基本上解析为Object.assign(如果可用)。

+0

是否存在除了使用babel库之外的对象传播的现有polyfill? – guest271314

+0

任何用作Object.assign的polyfill的东西。对象传播仅仅是合并对象。 –

+0

也许以前的评论措词不够。意味着在普通对象内使用传播或休息元素语法,而不使用babel。 – guest271314

1
<Link to="/home" children="Home" activeClassName="active"/>