DEV Community

sandeepsamanth
sandeepsamanth

Posted on

react day 1 jsx-rules

return single element (one parent element)

  • semantics section/article
  • Fragment - let's us group elements without adding extra nodes
  • camelCase property naming convention
<button onClick={myFunction}>click me</button>
Enter fullscreen mode Exit fullscreen mode
  • className instead of class
return <div className='someValue'>hello</div>;
Enter fullscreen mode Exit fullscreen mode

import React from 'react';
import ReactDOM from 'react-dom/client';

function BookList() {
  return (
    <section>
      <Book />
      <Book />
      <Book />
      <Book />
    </section>
  );
}

const Book = () => {
  return (
    <article className='book'>
      <Image />
      <Title />
      <Author />
    </article>
  );
};

const Image = () => (
  <img
    src='https://images-na.ssl-images-amazon.com/images/I/71m+Qtq+HrL._AC_UL900_SR900,600_.jpg'
    alt='Interesting Facts For Curious Minds'
  />
);
const Title = () => {
  return <h2>Interesting Facts For Curious Minds</h2>;
};
const Author = () => <h4>Jordan Moore </h4>;

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(<BookList />);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)