jaredpalmer / awesome-react-render-props

Awesome list of React components with render props
1.37k stars 111 forks source link

What the best way render props? #84

Closed nghiepdev closed 5 years ago

nghiepdev commented 5 years ago

Hi all,

I have two examples with render props and don't know What is the best way? Why? Different?

Example 1:

// Layout.jsx
const Layout = ({ children, aside }) => (
  <div>
      <header>My header</header>
      {aside}
      <main>
          {children}
      </main>
  </div>
);

// user.js
import Aside from './components/Layout';

const User = () => (
  <Layout aside={<Aside />}>
      My user page
  </Layout>
);

Example 2:

// Layout.jsx
const Layout = ({ children, aside: Aside }) => (
  <div>
      <header>My header</header>
      <Aside />
      <main>
          {children}
      </main>
  </div>
);

// user.js
import Aside from './components/Layout';

const User = () => (
  <Layout aside={Aside }>
      My user page
  </Layout>
);

Thank in advance!