【发布时间】:2021-10-14 02:37:24
【问题描述】:
使用 React Native Expo,我有一个 MapView 屏幕,它在底部屏幕上显示标记(标题、描述、图像等)的信息。目前我有一个功能,当按下标记时,标记信息将传递给名为 MarkerInfo 的变量并显示在底部屏幕上。但是,当组件初始化时,底页中不会显示任何信息。
我想显示一条提示用户选择标记的消息。
这是包含 pressMarker 函数的当前代码块:
// ## Attempting to set intial values prompting users to select a marker for more info
const state = {
MarkerInfo: {
PreviewTitle: "Select A Marker.",
Description: "Press on a marker to get location information"
}
};
// ## Without the code above this all works fine:
// ## Setting the currently selected marker as variable (in an array) "MarkerInfo".
const [MarkerInfo, setMarkerInfo] = useState([]);
const pressMarker = (i) => {
setMarkerInfo(i);
console.log(i)
return(MarkerInfo)
};
下面是标记信息数组的示例,当标记被按下时。
Object {
"Description": "Former historic palace housing huge art collection, from Roman
sculptures to da Vinci's 'Mona Lisa.",
"ImageUrl": "*** My firebase storage URL",
"Latitude": 48.86074344,
"Location": "Paris",
"Longitude": 2.337659481,
"PreviewTitle": "Louvre",
"Title": "Louvre Museum",
"id": 64,
"key": "63",
}
但是,在我击中标记之前,底部的工作表没有显示任何内容。所以看起来我对标记信息的初始变量定义没有像我希望的那样执行。
我需要对初始声明进行哪些更改?我也尝试过使用组件确实安装并返回初始标记信息的功能,但没有运气。
【问题讨论】:
标签: javascript react-native expo state use-state