Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
How to delay the API request to only work after finishing typing

i'm trying to use react-debounce-input ,which works great as a stand-alone piece of code but i just can't seem to integrate it with material UI Autocomplete component no matter what.

is there a way of debouncing my search input without it? can i use react-debounce with my current code?

the debounceinput component

          <DebounceInput
            minLength={2}
            debounceTimeout={300}
            type='text'
            placeholder='enter city'
            onChange={(e) => onSearch(e.target.value)}
          />

the entire code :

import React, { useEffect, useState } from 'react';
import { weatherService } from '../service/weather.service.js';
import { DayList } from '../cmps/DayList';
import Autocomplete from '@mui/material/Autocomplete';
import TextField from '@mui/material/TextField';

export const WeatherPage = () => {
  const [searchValue, setSearchValue] = useState(null);
  const [weather, setWeather] = useState([]);
  const [results, setResults] = useState([]);

  const onSearch = async (ev) => {
    const result = await weatherService.getLocationKey(ev);
    console.log('result:', result);
    setWeather(result);
  };

  weather.forEach((city) => {
    city.label = city.LocalizedName;
  });

  const handleChange = (key) => {
    console.log('key:', key);
    setSearchValue(key);
  };

  const onSubmitCity = async (searchValue) => {
    const city = await weatherService.getWeatherResults(searchValue);
    setResults(city);
  };

  return (
    <div>
      <div className='main-layout'>
        <div className='weather-page'>
          <div>WeatherPage</div>

          <Autocomplete
            disablePortal
            id='combo-box-demo'
            options={weather}
            clearOnBlur={false}
            onChange={(event, value) => handleChange(value.Key)} // prints the selected value
            sx={{ width: 300 }}
            renderInput={(params) => (
              <TextField
                {...params}
                label='City'
                type='text'
                placeholder='enter city'
                onChange={(e) => onSearch(e.target.value)}
              />
            )}
          />
          <button onClick={() => onSubmitCity(searchValue)}>Submit</button>
          <section>Lorem ipsum, dolor sit amet consectetur adipisicing</section>
          <button>Toggle Degrees</button>
          <DayList results={results} />
        </div>
      </div>
      <section className='footer'>Footer</section>
    </div>
  );
};

Any help appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!