Created
February 22, 2017 07:18
-
-
Save DimaDaxDadeco/a269a495a17b0abd8b5ed4276eff1fc1 to your computer and use it in GitHub Desktop.
This file contains 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 * as React from 'react'; | |
import { INewsItem } from '../../models/news'; | |
interface IProps { | |
items: INewsItem[]; | |
} | |
export default (props: IProps) => { | |
return ( | |
<div> | |
{ props.items.map((item, i) => ( | |
<div key={`news-item-${i}`}> | |
<span>{ item.title }</span> | |
</div> | |
)) | |
}! | |
</div> | |
); | |
} |
This file contains 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 * as React from 'react'; | |
import { asyncConnect } from 'redux-connect'; | |
import { connect } from 'react-redux'; | |
import { INews } from '../../models/news'; | |
import { getNews } from '../../redux/modules/news'; | |
import NewsComponent from '../../components/news'; | |
interface IProps { | |
news: INews; | |
} | |
interface AsyncProps { | |
store: { | |
dispatch: Redux.Dispatch; | |
} | |
} | |
class NewsContainer extends React.Component<IProps, {}> { | |
public render() { | |
return (<NewsComponent items={this.props.news.items} />); | |
} | |
} | |
const NewsConnected = connect<IProps, {}, IProps>(( | |
state: { news: INews }) => ({ | |
news: state.news, | |
}))(NewsContainer); | |
export const News = asyncConnect( | |
[{ | |
promise: (props: AsyncProps) => { | |
return props.store.dispatch(getNews()); | |
}, | |
}] | |
)(NewsConnected); |
This file contains 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 * as React from 'react'; | |
import { IndexRoute, Route } from 'react-router'; | |
import { App } from '../containers/app/app'; | |
import { Journal } from '../containers/journal/journal'; | |
import { News } from '../containers/news' | |
import { NewsCard } from '../containers/news_card/news_card' | |
export default ( | |
<Route path="/" component={App}> | |
<IndexRoute component={Journal} /> | |
<Route path="news" component={News} /> | |
<Route path="news/:id" component={NewsCard} /> | |
</Route> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment