Skip to content

Instantly share code, notes, and snippets.

@tyb
Created June 19, 2019 11:43
Show Gist options
  • Save tyb/bfcb1c86c9e3403ed2c175bffd27bd61 to your computer and use it in GitHub Desktop.
Save tyb/bfcb1c86c9e3403ed2c175bffd27bd61 to your computer and use it in GitHub Desktop.
react non semantic component, making div a component instead of li
const Article = (props) => {
// Notice: <li>s are gone
return <div class="article">
<h2 class="article__title">{ props.title }</h2>
{ /* ... */ }
</div>;
}
const ArticleList = (props) => {
return <div class="articles">
<ul class="article-list">
{ props.articles.map(article =>
<li class="article-list__item">
<Article title={article.title} { /* other props */ } />
</li>
) }
</ul>
{ /* ... */ }
</div>;
}
// And now you can easily render an article inside of a sidebar – have no idea why though
const Sidebar = (props) => {
return <div class="sidebar">
<div class="sidebar__article">
<Article title="Look ma" { /* other props */ } />
</div>
{ /* ... */ }
</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment