首页 > 解决方案 > 组件不会重新渲染

问题描述

所以我有一个带有多个选择选项的表单。 我的表格

我从发送动作的年份中选择一个选项并调用 api 以获取显示的品牌列表。

如果我选择一个品牌并尝试选择另一个年份,它是否必须在选择时再次进行api调用?但显示相同的品牌列表?

在我的渲染函数中:

<div className='form-div'>
    <Select defaultValue='-Year-' style = {{width:262}} className = 'formInput' onChange={this.handleYearSelection.bind(this)}>
      {getYear(this.props.year)}
    </Select>
    </div>
    <div className='form-div'>
    <Select defaultValue='Brand' disabled={!this.state.brandVisibility} style = {{width:129}} className = 'formInput' onChange={this.handleBrandSelection.bind(this)}>
      {getBrand(this.props.brand)}
    </Select>
    <Select defaultValue='Model' disabled={!this.state.modelVisibility} style = {{width:129}} className = 'formInput' onChange={this.handleModelSelection.bind(this)}>
      {getModel(this.props.model)}
    </Select>
  </div>

渲染功能之前:

handleYearSelection(year){
    this.setState({brandVisibility : true, year: year});
    this.props.requestYear(year);
  }

  handleBrandSelection(brand){
    this.setState({modelVisibility : true, brand: brand });
    this.props.requestBrand(brand);
  }

那么,我该如何解决这个问题

标签: reactjsreduxrenderredux-saga

解决方案


推荐阅读