why is there no render() in functional components

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



why is there no render() in functional components



I'm a bit confused why render is used in class components and not in functional. Within render we return jsx syntax and similarly even in functional we return jsx syntax. But why there is no render in functional components?





The function itself is the render method, except that it gets the props as the first argument instead of being able to access it at this.props like you do in stateful components.
– Tholle
Jul 10 at 14:06



this.props





See the docs for more info
– Alan Friedman
Jul 10 at 14:12





i hope the result of this search will help you diff between functional and stateful component
– Mayank Shukla
Jul 10 at 14:16





1 Answer
1



The function itself is the render method, except that it gets the props as the first argument instead of being accessible at this.props like it is in stateful components.


props


this.props




function StatelessPerson(props)
return <h1> props.name </h1>;


class StatefulPerson extends React.Component
render()
return <h1> this.props.name </h1>;



ReactDOM.render(
<div>
<StatelessPerson name="Foo" />
<StatefulPerson name="Bar" />
</div>,
document.getElementById("root")
);


<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id="root"></div>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS