Giter Site home page Giter Site logo

blog-autocomplete's People

Contributors

saaage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

blog-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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.