1

Something that's always confused me is how many React examples show everything as components. But's let's say I only need to include some simple HTML alongside my components, like:

class Homepage extends Component {
  render() {
    return (
      <Container>
        <Hero />
        <Features />
        <div className="copyright">Copyright Some Company Name.</div>
      </Container>
    );
  }
}

The div element will never be more than static text.

Should the <div> be moved into a pure component? Or is it ok to simplify the Homepage component by adding plain HTML this?

3
  • 1
    It is ok writing plain HTML Commented Apr 27, 2017 at 18:00
  • 1
    Looks fine to me. Commented Apr 27, 2017 at 18:01
  • 1
    It depends on if you want to reuse this block or not. Commented Apr 27, 2017 at 18:03

2 Answers 2

2

Sure it's ok. all in all it's HTML in the end. React components are set of html elements when you call the render function.

One rule of thumb i follow is: create a new component when you think a new responsibility is in order.

Sign up to request clarification or add additional context in comments.

Comments

2

That div is a component just like any other, except it is a "primitive" one. There should be no problem mixing the primitive components from HTML with your own custom components.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.