我正在将react-google-maps库用于一个项目,我找到了一个完美的例子来满足我的需求。它是下面的代码,正如您所看到的,它是一个类组件。
class Map extends Component {
constructor(props){
super(props);
this.map = React.createRef();
}
render() {
const MyGoogleMap = withScriptjs(
withGoogleMap(props => (
<GoogleMap
ref={map => {
this.map = map;
}}
/>
))
);
return(
<MyGoogleMap />
);
}
}
export default Map
我想在函数组件中迁移这个类。
我不知道如何实现功能组件的行是
this.map = React.createRef();
和
ref={map => { this.map = map }}
慕运维8079593
相关分类