I want to make a autocomplete input in ReactJS. Before I used ReactJS, I usually used jQuery for autocomplete. And just because I've been struggled with many of ReactJS' autocompletes and made errors in my website, I decided to return to jQuery's thing.
I usually write the code like common jQuery but this time I just got unusual error:
TypeError: Cannot read property 'version' of undefined at $.widget (home.js:5734)
at CarouselPage._callee$ (home.js:49729)
at tryCatch (home.js:46411)
at Generator.invoke [as _invoke] (home.js:46637)
at Generator.prototype.(/anonymous function) [as next] (http://localhost.mysite.com/js/home.js:46463:21)
at asyncGeneratorStep (home.js:49673)
at _next (home.js:49675)
at home.js:49675
at new Promise (<anonymous>)
at CarouselPage.<anonymous> (home.js:49675)
This is the code that I write:
import React, {Component} from 'react';
import $ from 'jquery-ui';
/* ... some codes ... */
async componentWillMount() {
$('#location').autocomplete({
source: '/thislocation/all/name'
});
}
/* ... more codes ... */
render() {
let {state} = this;
return (
<div className="carousel-home">
<input type="text" placeholder="Lokasi" name="location" id="location"
autoComplete="off"/>
</div>
in /thislocation/all/name
URI goes to my controller with getName()
function, I just created a hard-coded array to make sure this code works:
public function getName(){
try{
return response()->json(['test','123','234']);
} catch (Exception $exception){
return response()->json(['error' => $exception->getMessage()], 404);
}
}
What did I miss in this code?