4

I started work with google-map-react and found this line:

const AnyReactComponent = ({ text }) => <div>{text}</div>

What does it do?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Alexey Nikonov
  • 4,958
  • 5
  • 39
  • 66

1 Answers1

3

This is a stateless functional component (that is, the function is a render function, taking props as argument). The functionality could be rewritten like this:

class AnyReactComponent extends React.Component {
    render() {
       const { text } = this.props;

       return <div>{text}</div>;
    }
}
Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • But what is this stateless func component used for? if it doesnt render anything and hasnt any other method inside. Just to **clarify, for example**, if in an imaginary function we have `let array = []`, then we know it used later as a interjacent array to store some temporary data and perform some actions on it. Otherwise that array is unused and must be removed from code – Alexey Nikonov Aug 26 '18 at 18:35
  • i understood my question in the upper comment, so the answer: __stateless function component__ are used to be a component without any method, just render. **For example** we need in an imaginary network a profile page, so **an avatar** may be there a separate stateless component that **needed to be rendered** and nothing more – Alexey Nikonov Aug 26 '18 at 20:54