ViewBlog component renders a single blog article. It reads the article identifier from the URL, retrieves the corresponding content via getArticle(), and displays it.
Route
ViewBlog is mounted at /blog/:id in App.js using React Router v4’s render prop pattern:
src/App.js
/blog/netflix renders the Netflix article.
Component source
src/components/ViewBlog.js
How article lookup works
User navigates to a blog URL
A URL like
/blog/netflix matches the route /blog/:id. React Router extracts "netflix" as the id param.ViewBlog reads the route param
ViewBlog receives routeProps spread as props. The article ID is available at props.match.params.id.ViewBlog calls getArticle
The component calls
getArticle(id) from src/constants/articles.js. This function looks up the ID in the idsAndArticles map and returns the value — which is the article’s content property from the article module.Current articles
| ID | File | Route |
|---|---|---|
netflix | src/constants/articles/netflix.js | /blog/netflix |
Article module structure
Each article is a JavaScript module that exports an object. The netflix article is the only current example:src/constants/articles/netflix.js
The
date field in netflix.js is set to netflixTitle (the title string) instead of netflixDate. This is a bug in the source that causes the date metadata to display the title text instead of the date.Adding a new article
Create the article file
Create
src/constants/articles/my-article.js and export an object with title, date, and content:src/constants/articles/my-article.js
The article ID in the URL must exactly match the key used in
idsAndArticles. A mismatch causes getArticle to return undefined, which will cause a runtime error when ViewBlog tries to access .title and .context on it.