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>

The quesion is below:

<Link {...this.props} activeClassName="active"/>, what does the statement compile to es5, if this.props={to: "/home", children: "Home"}?

1
  • You can find out yourself: babeljs.io/repl . Commented Dec 30, 2016 at 1:44

2 Answers 2

2

Straight from the Babel homepage:

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

I omitted the _extends polyfill, it basically resolves to Object.assign if it is available.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there an existing polyfill for object spread that you are aware of other than using the babel library?
Anything that serves as polyfill for Object.assign. Object spread is nothing but merging objects.
Perhaps worded previous comment inadequately. Meant using spread or rest element syntax within a plain object, without using babel.
Oh I see. You have to use a transpiler for converting syntax features. I guess Babel is the most popular one these days. I don't really know or use any others.
Both object rest (var {foo, ...bar} = object;) and spread ({foo: 42, ...obj}) are part of the same proposal: github.com/sebmarkbage/ecmascript-rest-spread . " Can only certain portions of babel by extracted and utilized?" Yes, by default Babel does nothing. You have to enable the features you want to use. See babeljs.io/docs/plugins .
|
1
<Link to="/home" children="Home" activeClassName="active"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.