首页 > 解决方案 > 使用 react-navigation 导航会导致组件不显示数据,需要重新渲染

问题描述

当我使用 react-navigation 导航时,显示的屏幕(SearchPage - 无状态功能组件)有一个CategoriesMultiselect(类组件)缺少类别数据(视觉上)。数据肯定仍然存在,因为当我滚动页面时,数据会显示出来,因为它被重新渲染了。

searchPage当导航到(或重新呈现类别多选)时,我将如何导致重新呈现?

导航的代码:

import FBLoginButton from './button/view'
import React, { Component } from 'react'
import { View } from 'react-native'
import { Container, Text, Button } from 'native-base'
import VepoHeader from '../../formControls/header/view'
import { styles } from '../../style'

import { withNavigation } from 'react-navigation'

class LoginView extends Component {
    constructor(props) {
        super(props)
        this.buttonPress = this.buttonPress.bind(this)
      }

      buttonPress() {
        console.log('called')
        this.props.navigation.navigate('Search')
      }
  render() {
    return (
      <Container style={{ backgroundColor: '#27a562' }}>
        <Container
          style={{
            flex: 1,
            height: '100%',
            flexDirection: 'column',
            justifyContent: 'center',
            alignItems: 'center'
          }}>
          <FBLoginButton />
          <Text style={{ color: '#FFF', 
          marginTop: 20,
          marginBottom: 20 }}>OR</Text>
          <Button
            block
            style={{
              ...styles.labelHeight,
              borderRadius: 4,
              borderWidth: 0.5,
              borderColor: '#FFF',
              width: 250,
              marginLeft: 'auto',
              marginRight: 'auto',
              backgroundColor: 'transparent',

            }}
            onPress={this.buttonPress}>
            <Text style={{fontSize: 13.5}}>Continue without Login</Text>
          </Button>
        </Container>
      </Container>
    )
  }
}

export default withNavigation(LoginView)

导航到无状态功能 searchPage 组件后,我需要在 CategoriesMultiselect 上调用 forceupdate()。

我怎么做?

标签: react-nativereact-navigation

解决方案


推荐阅读