Search code examples
javascriptfluxreactjs-flux

React Flux Uncaught TypeError: _LocalityStore2.default.setSelectedLocality is not a function


I have HomeLayout from where I get redirected to MobileLocalityLayout which has a method selectLocality to set locality value to LocalityStore on clicking a link called "set locality". Now as soon as I select locality I am redirected to the HomeLayout and after that if press locality button again and select locality, I get following error:

Uncaught TypeError: _LocalityStore2.default.setSelectedLocality is not a function

However LocalityStore has the function setSelectedLocality.

Code Snippets:

HomeLayout :

<span class='selectLocalityBtn'><Link to="/selectLocality">Set Locality</Link></span>

MobileLocalityLayout:

selectLocality(val){
        this.setState({
            selectedLocality : val
        });
        LocalityStore.setSelectedLocality(val);
        browserHistory.push("/");
    }

LocalityStore:

setSelectedLocality(locality){
    this.setSelectedLocality = locality;
}

Am I implementing flux in wrong way. I don't understand what is _LocalityStore2 as I have LocalityStore and not LocalityStore2. Please help.


Solution

  • You have a typo in your code

    setSelectedLocality(locality){
        this.setSelectedLocality = locality;
    }
    

    please replace this.setSelectedLocality with this.selectedLocality