相关疑难解决方法(0)

React中的无限渲染

我有问题弄清楚为什么我的应用程序正在做无休止的渲染.

在Inside,我的有状态组件,我在componentDidMount方法中调用redux动作(调用componentWillMount也做无穷无尽的渲染)

class cryptoTicker extends PureComponent {
  componentDidMount() {
    this.props.fetchCoin()
    // This fetches some 1600 crypto coins data,Redux action link for the same in end
  }

  render() {
    return (
      <ScrollView>
        <Header />
        <View>
          <FlatList
            data={this.state.searchCoin ? this.displaySearchCrypto : this.props.cryptoLoaded}
            style={{ flex: 1 }}
            extraData={[this.displaySearchCrypto, this.props.cryptoLoaded]}
            keyExtractor={item => item.short}
            initialNumToRender={50}
            windowSize={21}
            removeClippedSubviews={true}
            renderItem={({ item, index }) => (
              <CoinCard
                key={item["short"]}
              />
            )} 
          />
        </View>
      </ScrollView>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

在CoinCard中我除此之外什么都不做(在Flat列表中注意CoinCard)

class CoinCard extends Component {
  render () { 
    console.log("Inside rende here") …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

6
推荐指数
1
解决办法
1352
查看次数

标签 统计

javascript ×1

react-native ×1

reactjs ×1