Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class App extends React.Component<Props, State> {
<div>
<h1>Mega App</h1>
Username: <input value={this.state.username} onChange={this.handleUserChange}/>
<ArticleList articles={this.props.articles}/>
<ArticleList articles={this.props.articles} toggleOpenItem={() => {}}/>
</div>
</Provider>
)
Expand Down
5 changes: 1 addition & 4 deletions src/article-list.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as React from 'react'
import Article from './article-new'
import {IArticle} from './article'
import withAccordion from './decorators/accordion'

interface Props {
articles: IArticle[]
toggleOpenItem: (article: IArticle) => void
openItemId?: string
}

class ArticleList extends React.PureComponent<Props> {
export default class ArticleList extends React.PureComponent<Props> {
render() {
const { articles, openItemId, toggleOpenItem } = this.props
return (
Expand All @@ -24,5 +23,3 @@ class ArticleList extends React.PureComponent<Props> {
)
}
}

export default withAccordion<any>(ArticleList)
4 changes: 2 additions & 2 deletions src/decorators/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface AdditionalProps {
toggleOpenItem: (item: IArticle) => void
}

export default function withAccordion<T extends AdditionalProps>(OriginalComponent: React.ComponentType<T>) {
return class Accordion extends React.Component<Exclude<T, AdditionalProps>, State> {
export default function withAccordion<T>(OriginalComponent: React.ComponentType<T & AdditionalProps>) {
return class Accordion extends React.Component<T, State> {
state: State = {
openItemId: undefined
}
Expand Down
8 changes: 6 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import articles from './fixtures.json'
import App from './app'
import {IArticle} from "./article";
import withAccordion from "./decorators/accordion";
import ArticleList from "./article-list";

ReactDOM.render(<App articles={articles}/>, document.getElementById('root'))
const ArticleListWithAccordion = withAccordion<{articles: IArticle[]}>(ArticleList);

ReactDOM.render(<ArticleListWithAccordion articles={articles}/>, document.getElementById('root'));