【问题标题】:Property not found - flowtype / react, using this未找到属性 - 流类型/反应,使用此
【发布时间】:2017-03-23 07:23:53
【问题描述】:

知道如何摆脱错误propertyunsubscribe: Property not found in FilterLink

class FilterLink  extends React.Component { // container component - provides data and behaviour for the used Link presentation component
  componentDidMount() {
    this.unsubscribe= store.subscribe(()=> this.forceUpdate());  // FLOW ERROR: property `unsubscribe`Property not found in ...

    // this is needed because if the parent component does not update when then
    // store changes, this component would render a stale value
  };
  componentWillUnmount() {
    this.unsubscribe();
  }
  render(){
    const props = (this.props:{filter:State$VisibilityFilter,children:React$Element<*>});
    const state = store.getState();
    return (
      <Link
        active ={props.filter===state.visibilityFilter}
        onClick = {()=> store.dispatch (({ type:'SET_VISIBILITY_FILTER', filter: props.filter }:Action$SetVisibilityFilter))}
        children= {props.children} />
    )
  };
};

【问题讨论】:

    标签: reactjs flowtype


    【解决方案1】:

    再次,我得到了 IRC 的 GreenJello 的帮助,谢谢!

    这是解决方案:

      unsubscribe:Function; // SOLUTION !!
      componentDidMount() {
        this.unsubscribe= store.subscribe(()=> this.forceUpdate());
        // this is needed because if the parent component does not update when then
        // store changes, this component would render a stale value
      };
      componentWillUnmount() {
        this.unsubscribe();
      }
    

    这也有帮助:https://flowtype.org/docs/react.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2016-08-29
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多