Created
May 22, 2015 16:48
-
-
Save tsingson/9869a48da12995cefd8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import Router, { Route, DefaultRoute, RouteHandler, Link } from 'react-router'; | |
var data = require('./data'); | |
class Item extends Component { | |
constructor(props,context) { | |
super(props); | |
//this.state = this.getStateFromStore(); | |
} | |
render () { | |
var params = this.context.router.getCurrentParams(); | |
var category = data.lookupCategory(params.category); | |
var item = data.lookupItem(params.category, params.name); | |
return ( | |
<div> | |
<h2>{category.name} / {item.name}</h2> | |
<p>Price: ${item.price}</p> | |
</div> | |
); | |
} | |
} | |
// why it work but not define inside class | |
Item.contextTypes = { | |
router: React.PropTypes.func.isRequired | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment