我试图通过导航事件传递一个数组,然后将值存储在一个变量中。此变量与 map 函数一起使用来生成渲染项,该渲染项在 react-native-swiper 的 swiper 组件中传递。下面是代码的渲染函数示例。
return (
<View style={{flex:1}}>
<NavigationEvents onWillFocus={(payload)=>{
// console.log(payload.action.params)
if(payload.action.params){
// console.log("Printing Here: ", payload.action.params.shlok)
//console.log(payload.action.params.path)
setPath(payload.action.params.path)
setActiveSlide(payload.action.params.index)
}}
}
/>
{/* <ReadScreenComponent shlok = {55} chapter = {1}/> */}
<Swiper loop={false}
showsPagination = {false}
ref = {swiperRef}
index = {activeSlide}
onIndexChanged = {(index)=>{setActiveSlide(index)}}
>
{_renderItem}
</Swiper>
</View>
);
这是我更新渲染项的方式。
useEffect(()=>{
var _renderItem = path.map((item, index) => {
return (
<ReadScreenComponent
shlok = {item.shlok}
chapter = {item.chapter}
forwardAction = {forwardAction}
backwardAction = {backwardAction}
/>
)
});
console.log(_renderItem)
},[path])
尽管 renderItem 值已更新,但渲染并没有改变。另外我想提一下我正在使用 react-navigation 并且它在两个选项卡之间导航。在第一个实例中,该值正在更新。但不是在那之后。在这方面的任何帮助都会非常有帮助..在此先感谢