Skip to content

Commit

Permalink
part 02
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Sep 1, 2017
1 parent 6911ab1 commit 2fc830f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import './App.css';
import Stories from './Stories';

const App = ({ stories }) =>
<div className="app">
<Stories stories={stories} />
</div>

export default App;
15 changes: 15 additions & 0 deletions src/components/Stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import './Stories.css';
import Story from './Story';

const Stories = ({ stories }) =>
<div className="stories">
{(stories || []).map(story =>
<Story
key={story.objectID}
story={story}
/>
)}
</div>

export default Stories;
25 changes: 25 additions & 0 deletions src/components/Story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import './Story.css';

const Story = ({ story }) => {
const {
title,
url,
author,
num_comments,
points,
} = story;

return (
<div className="story">
<span>
<a href={url}>{title}</a>
</span>
<span>{author}</span>
<span>{num_comments}</span>
<span>{points}</span>
</div>
);
}

export default Story;
25 changes: 23 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import App from './components/App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
const stories = [
{
title: 'React',
url: 'https://facebook.github.io/react/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
}, {
title: 'Redux',
url: 'https://github.com/reactjs/redux',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
];

ReactDOM.render(
<App stories={stories} />,
document.getElementById('root')
);
registerServiceWorker();

0 comments on commit 2fc830f

Please sign in to comment.