首页 > 解决方案 > 我在使用 react-native-maps 参考时遇到问题

问题描述

我正在使用功能组件并在 MapView 组件中使用 useRef。但是这些功能不是通过参考来的,有人知道如何纠正吗?

代码示例

import React, {useRef} from 'react'       //version 16.13.1
import MapView from 'react-native-maps'   //version 0.27.1
import {View} from 'react-native'         //version 0.63.2
    
    const Map = () => {
    
        const mapRef = useRef(null);
    
        return (
           <View>
             <MapView ref={mapRef}/>
           </View>
        )
    }

当我尝试访问 mapRef.current、fitToCoodinates、getCamera、animateToRegion 等时......未定义。但我可以从 mapRef.current 获得道具。有人能帮我吗?我想要功能,而不是属性。

标签: reactjsreact-nativerefreact-native-maps

解决方案


推荐阅读