in React JS by
Q:

What are pure functional Components?

▼ Show 1 Answer

0 votes
by

Traditional React Components as we have seen so far are making a class with class Example extends React.Component or React.createClass(). These make stateful components on the off chance that we at any point set the state (i.e. this.setState(), getInitialState(), or this.state = {} inside a constructor()). 

In the event that we have no expectation for a Component to require state, or to require lifecycle methods, we can really compose Components with a pure function, consequently the expression "pure function Component":

1

2

3

4

5

6

7

8

9

10

function Date(props)

{

let {msg="The date is:"} = props

let now = new Date()

return <div>

<span> {msg}</span>

<time> {now.toLocaleDateString()}</time>

</div>

}

This function that returns a React Element can be used wherever we see fit:

1

DOM.render(<div> <Date msg="Today is"/></div>)

You might notice that also takes a prop – we can still pass information into the Component.

React JS
Learn More with Madanswer

Related questions

0 votes
asked Jan 30 in React JS by rajeshsharma
  • #pure-component
  • react-pure-component
  • reactjs
  • react
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
...