blog-autocomplete's People
Forkers
niyogakiza pbrocks moughamir tdurant72 marhdz creatigent nv1028 anish8506 vincetita 1linkovdim max-content carloswilsonperez mastrobirraio fliodhaisblog-autocomplete's Issues
Curious to better understand search.value and this.search
Hello Stefan, I was researching how to do do suggestions for a music search bar and I came across your post on Medium, I am trying to convert the component from a class to functional component, however, I'm stumped by the " this.search.value," as well as "this.search". Would you mind (if you can) explaining how I would change this to utilize it in a class component? This is what I got so far.
`const { API_KEY } = process.env;
const API_URL = 'http://api.musicgraph.com/api/v2/artist/suggest';
const Search = () => {
const [state, setState] = useState({
query: '',
results: [],
});
const getInfo = () => {
axios
.get(${API_URL}?api_key=${API_KEY}&prefix=${state.query}&limit=7
)
.then(({ data }) => {
setState((prevState) => ({
...prevState,
results: data.data,
}));
});
};
const handleInputChange = () => {
setState(
(prevState) => ({
...prevstate,
query: this.search.value, //would I need a variable for search in a functional component?
}),
() => {
if (state.query && state.query.length > 1) {
if (state.query.length % 2 === 0) {
getInfo();
}
} else if (!state.query) {
}
}
);
};
return (
<input
placeholder='Search for...'
ref={(input) => (this.search = input)} /* No idea how to input 'search' for a functional component, would I need to create a variable for this? */
onChange={() => handleInputChange()}
/>
);
};
export default Search;`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.