npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-mui-input-search-debounce

v1.0.1

Published

Componente de búsqueda con autocompletado, selectores y enrutamiento, construido con MUI y React Router.

Downloads

209

Readme

🔍 react-mui-input-search-debounce

Search component with autocomplete, category selector, and routing, built with Material-UI (MUI) and React Router. Includes debounce to optimize requests and supports light/dark themes.

Component for use in two themes

| Modo claro | Modo oscuro | | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | | Input Search white | Input Search black |


📦 Installation

npm install react-mui-input-search-debounce

or with Yarn:

yarn add react-mui-input-search-debounce

Required peer dependencies

Make sure you have the following libraries installed in your project:

react >= 17.0.0
react-dom >= 17.0.0
@mui/material >= 5.0.0
@mui/icons-material >= 5.0.0
@emotion/react >= 11.0.0
@emotion/styled >= 11.0.0
react-router-dom >= 6.0.0

🚀 Basic Usage

import { InputSearch } from 'react-mui-input-search-debounce';

function App() {
  return (
    <InputSearch
      labelText="Search in Portfolio, Blog, Startups..."
      noResultMessage="No results found"
      menuItems={[
        { label: 'All content', value: '' },
        { label: 'Technical Portfolio', value: 'portfolio' },
        { label: 'Startups', value: 'entrepreneurships' },
        { label: 'Blog', value: 'blog' },
      ]}
      routeMap={{
        '': '/all/search',
        portfolio: '/portfolio/search',
        entrepreneurships: '/entrepreneurships/search',
        blog: '/blog/search',
      }}
      fetchSuggestions="https://api.example.com/suggestions?q="
    />
  );
}

📋 Props


Prop Type Required Description


labelText string Yes Placeholder text displayed when the input is empty.

menuItems { label: string; value: string }[] Yes List of category selector options. The first item is used as default.

fetchSuggestions string | ((query: string) => Promise<string[]>) Yes* Base URL or custom function returning suggestions.

routeMap Record<string, string> No Route mapping per category.

noResultMessage string No Message displayed when there are no suggestions. Default: "No results".

Note: The category selector is only displayed if menuItems.length >= 2.


🧠 Behavior

  • Debounce: 300 ms after the user stops typing.
  • Conditional selector: Only shown if more than one category exists.
  • React Router integration: Navigates with ?q=term&p=1.
  • Autocomplete: Displays suggestions or noResultMessage.
  • Light/Dark theme: Automatically adapts to the active MUI theme.

Input Search black


🔗 Routing (routeMap)

const menuItems = [
  { label: 'All', value: '' },
  { label: 'Blog', value: 'blog' },
];

const routeMap = {
  '': '/search/all',
  blog: '/blog/search',
};

If routeMap is not provided, /all/search is used by default.


🔌 Suggestions Source (fetchSuggestions)

As a string (base URL)

fetchSuggestions="https://myapi.com/suggest?q="

The component builds the final URL as:

${baseUrl}${encodedQuery}&category=${currentCategory}

As a custom function

fetchSuggestions={async (query) => {
  const res = await fetch(`/api/search?q=${query}`);
  const data = await res.json();
  return data.titles; // must return string[]
}}

🎨 Style Customization

You can use the sx prop, a custom MUI theme, or override classes such as .MuiAutocomplete-root.


📁 Internal Structure

src/
  components/
    surfaces/
      appbar/
        inputs/
          components/
            SearchButton.tsx
            SearchInput.tsx
            SearchSelect.tsx
          hooks/
            useDebounce.ts
            useSearchInput.ts
          services/
            api/
              suggestionsService.ts
          styles/
            SearchInput.styles.ts
          index.ts

⚙️ Full Example with Routing

import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { InputSearch } from 'react-mui-input-search-debounce';

const menuItems = [
  { label: 'All', value: '' },
  { label: 'Projects', value: 'projects' },
];

const routeMap = {
  '': '/search',
  projects: '/projects/search',
};

function App() {
  return (
    <BrowserRouter>
      <InputSearch
        labelText="Search..."
        menuItems={menuItems}
        routeMap={routeMap}
        fetchSuggestions="https://api.example.com/suggest?q="
        noResultMessage="No suggestions found"
      />
      <Routes>
        <Route path="/search" element={<SearchResults />} />
        <Route path="/projects/search" element={<ProjectsResults />} />
      </Routes>
    </BrowserRouter>
  );
}

🧪 Additional Notes

  • The suggestions API must return string[].
  • The parameter p=1 is automatically added if it does not exist.
  • If q or p is missing, the component redirects to /.
  • The debounce delay can be modified by editing useDebounce (if cloning the repository).

📄 License

MIT © BlackyCoder


Made with ❤️ for the React and MUI community.