Skip to content

Instantly share code, notes, and snippets.

@tsingson
Created May 22, 2015 16:48
Show Gist options
  • Save tsingson/9869a48da12995cefd8a to your computer and use it in GitHub Desktop.
Save tsingson/9869a48da12995cefd8a to your computer and use it in GitHub Desktop.
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