2016-11-20 47 views
1

任何想法如何擺脫錯誤property退訂: 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} /> 
    ) 
    }; 
}; 

回答

2

再次,我在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