Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@rtd/use-suggestions
Advanced tools
A React hook for fetching search suggestions from a Fastify API. This package includes a custom hook, types, and constants to simplify integration with your React/TypeScript projects.
A React hook for fetching search suggestions from a Fastify API. This package includes a custom hook, types, and constants to simplify integration with your React/TypeScript projects.
To install the package locally, you can use yarn add
or npm install
with a local file path:
yarn add @rtd/use-suggestions
or
npm install @rtd/use-suggestions
To add this package as a submodule in your project, use the following commands:
git submodule add -b <tag> https://github.com/your-username/use-suggestions.git src/hooks/use-suggestions
git submodule update --init --recursive
cd src/hooks/use-suggestions
git checkout <tag>
Replace <tag>
with the tag of the latest release you want to use.
cd ../../..
Add the following line to your .eslintignore
| .eslintrc.json
file:
"ignorePatterns": ["node_modules/", "src/hooks/useSuggestions/**/*"],
package.json
"dependencies": {
"use-suggestions": "file:src/hooks/use-suggestions"
}
Import the useSuggestions
hook, types, and constants in your React component:
import React, { useState } from 'react'
import {
useSuggestions,
DEBOUNCE_TIME_IN_MS,
SuggestionsOptions,
ConfigObject,
SearchableSuggestion,
} from '@rtd/use-suggestions'
Here’s an example of how to use the useSuggestions
hook in a React component:
const SuggestionComponent: React.FC = () => {
const [query, setQuery] = useState('')
const options: SuggestionsOptions = {
includeStops: true,
debounceTime: DEBOUNCE_TIME_IN_MS,
}
const baseUrl = 'https://your-api-base-url.com'
const namespace = 'api/v1'
const { suggestions, isLoading, error } = useSuggestions(
query,
options,
{ baseUrl, namespace }
)
return (
<div>
<input
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search for suggestions"
/>
{isLoading && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
<ul>
{suggestions.map((suggestion: SearchableSuggestion) => (
<li key={suggestion.id}>{suggestion.name}</li>
))}
</ul>
</div>
)
}
export default SuggestionComponent
useSuggestions
Fetches search suggestions from the API.
Parameters:
rawQuery: string
- The search query string.options: SuggestionsOptions
- Configuration options for the suggestions.config: ConfigObject
- Object that contains the base URL for the API and namespace (optional).Returns:
suggestions: SearchableSuggestion[]
- An array of suggestions.isLoading: boolean
- Loading state.error: Error | null
- Error state.The package includes several types to help with type safety in your project:
SuggestionsOptions
Configuration options for the suggestions.
interface SuggestionsOptions {
includeStops?: boolean
includeRoutes?: boolean
includeLocations?: boolean
includeDestinations?: boolean
includeConcerts?: boolean
location?: {
lat: number
lng: number
}
debounceTime?: number
}
SearchableSuggestion
Base interface for a searchable suggestion.
interface SearchableSuggestion {
suggestionType: SuggestionType
name: string
label: string
slug: string
lat: number
lng: number
searchTerms: string[]
}
The package includes the following constants:
DEBOUNCE_TIME_IN_MS
Default debounce time for the search query.
export const DEBOUNCE_TIME_IN_MS = 432
To build the package, run:
yarn build
This will compile the TypeScript files and output the results in the dist
directory.
This project is licensed under the MIT License.
FAQs
A React hook for fetching search suggestions from a Fastify API. This package includes a custom hook, types, and constants to simplify integration with your React/TypeScript projects.
The npm package @rtd/use-suggestions receives a total of 306 weekly downloads. As such, @rtd/use-suggestions popularity was classified as not popular.
We found that @rtd/use-suggestions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.