4

我开始使用google-map-react并发现这一行:

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

它有什么作用?

4

1 回答 1

3

这是一个无状态的函数组件(即函数是一个render函数,props作为参数)。功能可以这样重写:

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

       return <div>{text}</div>;
    }
}
于 2018-07-27T10:42:33.047 回答