I'm very new to react, and got a bit stuck already. I've made a component for an Article Topper that's repeated many times across the site. It has a logo, a title, and a few share buttons and just sits above the article with the name of the article.
What I want to do is update the title name when I call the component, as each article will have a different name.
constructor(props) {
super(props);
this.state = {
topper: []
};
}
render() {
return (
<div className="articletopper">
<div className="left-cell">
<p>
<img
className="logo"
alt=""
src={require("../images/logo.png")}
/>
{this.state.topper}
</p>
</div> ...
Then in the actual page I want to call this and update the topper state.
render() {
return (
<div className="Team">
<Articletopper>Title of Article?</Articletopper>
</div>
);
}
}
I am aware you are not supposed to update state when you call a component, just wondered if there was a way. The purpose of this is just to make the code cleaner when creating a new article.
Thanks in advance for any help.
EDIT: Thanks for the responses, sorry if I wasn't clear. I want to update the title of the article without pasting tons of html each time. I think I need to use props based on what other people have said. For example I want to do:
<ArticleTopper> Article 1 Title </ArticleTopper>
<p> Article1... </p>
<ArticleTopper> Article 2 Title </ArticleTopper>
<p> Article2... </p>
and so on...