jhegedus
jhegedus

Reputation: 20653

Property not found - flowtype / react, using this

Any idea how to get rid of the error 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} />
    )
  };
};

Upvotes: 2

Views: 1280

Answers (1)

jhegedus
jhegedus

Reputation: 20653

again, i got help from GreenJello in IRC, thanks !

this is the solution:

  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();
  }

this helped too : https://flowtype.org/docs/react.html

Upvotes: 2

Related Questions