I don't if this is a "Reacty" solution but I need to get parent component's class name from child component and here is why. If you can provide a different approach to this solution, I would be greatful.
I have the following components:
- ArticleHeader
- ArticleMeta
- ArticleBody
- ArticleImage
- Article
The Article component currently includes all the other components but I want to change that. I want my Article component to be like this:
render() {
return (
<article className={this.props.className}>
{this.props.children}
</article>
);
}
And I want someone to write something like:
<Article className="news-single">
<ArticleImage image="someimage.jpg" />
<ArticleHeader title="Test" />
<ArticleBody> <p>loren ipsum</p> </ArticleBody>
</Article>
I want ArticleImage, ArticleHeader, and ArticleBody to inherit className of parent so I can have classnames such as:
.news-single
.news-single-header
.news-single-image
.news-single-body
How can I get the parent component's className from child component?