I want to do something like this
var App = React.createClass({
render: function() {
return (
<CountryAutoComplete />
)
}
});
Different app
var App2 = React.createClass({
render: function() {
return (
<CountryAutoComplete />
)
}
});
Here is a simple Autocomplete (Not the entire file)
var AutoComplete = React.createClass({
componentDidMount: function() {
$(this.getDOMNode()).typeahead(this.props);
},
render: function() {
return (
<input type="text" class="typeahead" onChange={this.props.onChange} />
);
}
});
The CountryAutoComplete would be something like this to be self contained.
var CountryAutoComplete = React.createClass({
search: function(country, process) {
// Make an ajax call and return the data. No other components needed
$.ajax({
url: '/country' + '?search=' + country
}).then(process);
},
render: function() {
return (
<AutoComplete onChange={this.props.onChange} source={this.search} />
);
}
});
Based on the Flux docs, it looks like anything with an API call needs to go through the
actions -> API -> Dispatcher -> stores -> component
That makes the CountryAutoComplete tied to a specific app because the actions, Dispatcher and stores are specific to the App. What is the best way to make this component reusable across apps?