Languages
[Edit]
EN

React - render props (functional component)

0 points
Created by:
p_agon
589

In this article, we would like to show you how to render functional props in React.

Below we create Container functional component which renders name and two children <div> elements passed as props.

Runnable example:

// ONLINE-RUNNER:browser;

// Note: Uncomment import lines while working React project.
// import React from 'react';
// import ReactDOM from 'react-dom';

const Container = (props) => {
    return (
        <div>
          <div>{props.name}</div>
          <div>{props.children}</div>
        </div>
    );
}

const App = () => {
    return (
        <Container name="Property name ...">
          <div>Children text ...</div>
          <div>Children text ...</div>
        </Container>
    );
};

const root = document.querySelector('#root');
ReactDOM.render(<App />, root );

See also

  1. React - render props (class component) 

Alternative titles

  1. React - pass children elements to functional component
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join