anonymous / app.js
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

How to use Twitter Typeahead with react

View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
 
var TypeaheadInput = React.createClass({
componentDidMount: function () {
$(this.refs.input.getDOMNode()).typeahead(
{ hint: true, highlight: true, minLength: 1 },
{ name: 'states', displayKey: 'value', source: substringMatcher(this.props.options)}
)
.on("typeahead:autocompleted",this.props.onAutocompleted);
},
render: function() {
return ( <input type="text" ref="input" /> );
}
});
 
var ExampleApplication = React.createClass({
render: function() {
var bls = function () { console.log("bla"); }
return (
<div>
<TypeaheadInput onAutocompleted={bls} options={states} />
</div>
);
}
});
 
React.renderComponent( <ExampleApplication />, document.getElementById('container'));
View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Typeahead</title>
<script src="jquery-2.1.1.min.js"></script>
<script src="typeahead.jquery.min.js"></script>
</head>
 
<body>
<div id="container">
</div>
<script src="react-with-addons.min.js"></script>
<script src="JSXTransformer.js"></script>
<script type="text/jsx" src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.