Using timers

When someone opens the search panel and starts typing, we want to respond to them but we don’t want to send a search query to the database after every key press. Instead, it is better to wait for the typing to pause and then query the database. When a user starts typing, we can set a timer. The timer is reset if the user types another letter before it finishes. When the timer is finally up, the search request is sent to the database.

With the Excellence folder open in VS Code, open the terminal by clicking the "View" option and choosing "Terminal." Run the start script using the npm run start command. The start script will watch for any changes in the code and recompile it.

Inside the theme folder, open the src folder. Open the modules folder and then open Search.js.

In the previous lesson, we created a property for the input element in the constructor called searchInput.

Get hands-on with 1200+ tech skills courses.