A JavaScript module that helps anyone build recent searches functionality.
Building recent searches experience can be trickier than you think, recent-searches module helps you easily build that experience and handle the edge cases while also giving you flexibility on how to rank those suggestions. Since I couldn't find a good existing solution I decided to build one.
recent-searches is a module that handles storing, retrieving and ranking of recent searches. If available, it uses localStorage to store suggestions cross sessions and in the rare cases where it might not be available uses a fallback memory storage, thus loosing it's cross session functionality.
The module handles expiry of searches, ranking of results and degrading their ranking through their lifecycle as well as a simple prefix search.
recent-searches is published on npm's public registry, you can install it as a dependancy of your project with the following command.
npm install --save recent-searchesInitializing the module
import RecentSearches from 'recent-searches'
const searches = new RecentSearches({
ttl: number, // Optional: ttl of searches in milliseconds, default to 1h (1000 * 60 * 60)
limit: number, // Optional: max number of entries that will be persisted, defaults is 10
namespace: string, // Optional: custom localStorage namespace
rankBy: string // Optional: ranking strategy of recent searches, "PROXIMITY" | "TIME" | "PROXIMITY_AND_TIME", default is "PROXIMITY_AND_TIME"
})
Setting and retrieving relevant searches.
// To retrieve searches for a given query
const previousSearchesForJohn = searches.getRecentSearches("John")
// [{query: "John", timestamp: ...}, {query: "Marc John", timestamp: ...}]
// To set a recent search
searches.setRecentSearch("John", resultData)
This is the list of props that you should probably know about. There are some advanced props below as well.
function({})| required
This is called with an object. Read more about the properties of this object in the section "Children Function".
function(item: any)| defaults to:i => (i == null ? '' : String(i))
Used to determine the string value for the selected item (which is used to
compute the inputValue).
function(selectedItem: any, stateAndHelpers: object)| optional, no useful default
Called when the user selects an item and the selected item has changed. Called
with the item that was selected and the new state of recent-searches. (see
onStateChange for more info on stateAndHelpers).
selectedItem: The item that was just selectedstateAndHelpers: This is the same thing your children function is
called with (see Children Function)
function(state: object, changes: object)| optional
π¨ This is a really handy power feature π¨
This function will be called each time recent-searches sets its internal state
(or calls your onStateChange handler for control props). It allows you to
modify the state change that will take place which can give you fine grain
control over how the component interacts with user updates without having to
use Control Props. It gives you the current state and the
state that will be set, and you return the state that you want to set.
state: The full current state of recent-searches.changes: These are the properties that are about to change. This also has a
type property which you can learn more about in the
stateChangeTypes section.const ui = (
<recent-searches stateReducer={stateReducer}>{/* your callback */}</recent-searches>
)
function stateReducer(state, changes) {
// this prevents the menu from being closed when the user
// selects an item with a keyboard or mouse
switch (changes.type) {
case recent-searches.stateChangeTypes.keyDownEnter:
case recent-searches.stateChangeTypes.clickItem:
return {
...changes,
isOpen: state.isOpen,
highlightedIndex: state.highlightedIndex,
}
default:
return changes
}
}
NOTE: This is only called when state actually changes. You should not attempt to use this to handle events. If you wish to handle events, put your event handlers directly on the elements (make sure to use the prop getters though! For example:
<input onBlur={handleBlur} />should be<input {...getInputProps({onBlur: handleBlur})} />). Also, your reducer function should be "pure." This means it should do nothing other than return the state changes you want to have happen.
any| defaults tonull
Pass an item or an array of items that should be selected when recent-searches is initialized.
string| defaults to''
This is the initial input value when recent-searches is initialized.
number/null| defaults todefaultHighlightedIndex
This is the initial value to set the highlighted index to when recent-searches is initialized.
boolean| defaults todefaultIsOpen
This is the initial isOpen value when recent-searches is initialized.
number/null| defaults tonull
This is the value to set the highlightedIndex to anytime recent-searches is reset,
when the the selection is cleared, when an item is selected or when the inputValue is changed.
boolean| defaults tofalse
This is the value to set the isOpen to anytime recent-searches is reset, when the
the selection is cleared, or when an item is selected.
function(prevItem: any, item: any)| defaults to:(prevItem, item) => (prevItem !== item)
Used to determine if the new selectedItem has changed compared to the previous
selectedItem and properly update recent-searches's internal state.
function({/* see below */})| default messages provided in English
This function is passed as props to a Status component nested within and
allows you to create your own assertive ARIA statuses.
A default getA11yStatusMessage function is provided that will check
resultCount and return "No results." or if there are results but no item is
highlighted, "resultCount results are available, use up and down arrow keys to
navigate." If an item is highlighted it will run itemToString(highlightedItem)
and display the value of the highlightedItem.
The object you are passed to generate your status message has the following properties:
| property | type | description |
|---|---|---|
highlightedIndex |
number/null |
The currently highlighted index |
highlightedItem |
any |
The value of the highlighted item |
inputValue |
string |
The current input value |
isOpen |
boolean |
The isOpen state |
itemToString |
function(any) |
The itemToString function (see props) for getting the string value from one of the options |
previousResultCount |
number |
The total items showing in the dropdown the last time the status was updated |
resultCount |
number |
The total items showing in the dropdown |
selectedItem |
any |
The value of the currently selected item |
function(selectedItem: any, stateAndHelpers: object)| optional, no useful default
Called when the user selects an item, regardless of the previous selected item.
Called with the item that was selected and the new state of recent-searches. (see
onStateChange for more info on stateAndHelpers).
selectedItem: The item that was just selectedstateAndHelpers: This is the same thing your children function is
called with (see Children Function)
function(changes: object, stateAndHelpers: object)| optional, no useful default
This function is called anytime the internal state changes. This can be useful
if you're using recent-searches as a "controlled" component, where you manage some or
all of the state (e.g. isOpen, selectedItem, highlightedIndex, etc) and then
pass it as props, rather than letting recent-searches control all its state itself.
The parameters both take the shape of internal state ({highlightedIndex: number, inputValue: string, isOpen: boolean, selectedItem: any}) but differ
slightly.
changes: These are the properties that actually have changed since the last
state change. This also has a type property which you can learn more about
in the stateChangeTypes section.stateAndHelpers: This is the exact same thing your children function is
called with (see Children Function)Tip: This function will be called any time any state is changed. The best way to determine whether any particular state was changed, you can use
changes.hasOwnProperty('propName').
NOTE: This is only called when state actually changes. You should not attempt to use this to handle events. If you wish to handle events, put your event handlers directly on the elements (make sure to use the prop getters though! For example:
<input onBlur={handleBlur} />should be<input {...getInputProps({onBlur: handleBlur})} />).
function(inputValue: string, stateAndHelpers: object)| optional, no useful default
Called whenever the input value changes. Useful to use instead or in combination
of onStateChange when inputValue is a controlled prop to
avoid issues with cursor positions.
inputValue: The current value of the inputstateAndHelpers: This is the same thing your children function is
called with (see Children Function)
number| optional, defaults the number of times you call getItemProps
This is useful if you're using some kind of virtual listing component for
"windowing" (like
react-virtualized).
number| control prop (read more about this in the Control Props section)
The index that should be highlighted
string| control prop (read more about this in the Control Props section)
The value the input should have
boolean| control prop (read more about this in the Control Props section)
Whether the menu should be considered open or closed. Some aspects of the
recent-searches component respond differently based on this value (for example, if
isOpen is true when the user hits "Enter" on the input field, then the item at
the highlightedIndex item is selected).
any/Array(any)| control prop (read more about this in the Control Props section)
The currently selected item.
string| defaults to a generated ID
You should not normally need to set this prop. It's only useful if you're server
rendering items (which each have an id prop generated based on the recent-searches
id). For more information see the FAQ below.
string| defaults to a generated ID
Used for aria attributes and the id prop of the element (input) you use
getInputProps with.
string| defaults to a generated ID
Used for aria attributes and the id prop of the element (label) you use
getLabelProps with.
string| defaults to a generated ID
Used for aria attributes and the id prop of the element (ul) you use
getMenuProps with.
function(index)| defaults to a function that generates an ID based on the index
Used for aria attributes and the id prop of the element (li) you use
getInputProps with.
window| defaults towindow
This prop is only useful if you're rendering recent-searches within a different window context from where your JavaScript is running; for example, an iframe or a shadow-root. If the given context is lacking document and/or add|removeEventListener on its prototype (as is the case for a shadow-root) then you will need to pass in a custom object that is able to provide access to these properties for recent-searches.
function(stateAndHelpers: object)| optional
A helper callback to help control internal state of recent-searches like isOpen as
mentioned in this issue. The
same behavior can be achieved using onStateChange, but this prop is provided
as a helper because it's a fairly common use-case if you're controlling the
isOpen state:
const ui = (
<recent-searches
isOpen={this.state.menuIsOpen}
onOuterClick={() => this.setState({menuIsOpen: false})}
>
{/* your callback */}
</recent-searches>
)
This callback will only be called if isOpen is true.
function(node: HTMLElement, menuNode: HTMLElement)| defaults to internal implementation
This allows you to customize how the scrolling works when the highlighted index
changes. It receives the node to be scrolled to and the root node (the root
node you render in recent-searches). Internally we use
compute-scroll-into-view
so if you use that package then you wont be adding any additional bytes to your
bundle :)
There are a few props that expose changes to state
(onStateChange and stateReducer).
For you to make the most of these APIs, it's important for you to understand
why state is being changed. To accomplish this, there's a type property on the
changes object you get. This type corresponds to a
recent-searches.stateChangeTypes property.
The list of all possible values this type property can take is defined in
this file
and is as follows:
recent-searches.stateChangeTypes.unknownrecent-searches.stateChangeTypes.mouseUprecent-searches.stateChangeTypes.itemMouseEnterrecent-searches.stateChangeTypes.keyDownArrowUprecent-searches.stateChangeTypes.keyDownArrowDownrecent-searches.stateChangeTypes.keyDownEscaperecent-searches.stateChangeTypes.keyDownEnterrecent-searches.stateChangeTypes.clickItemrecent-searches.stateChangeTypes.blurInputrecent-searches.stateChangeTypes.changeInputrecent-searches.stateChangeTypes.keyDownSpaceButtonrecent-searches.stateChangeTypes.clickButtonrecent-searches.stateChangeTypes.blurButtonrecent-searches.stateChangeTypes.controlledPropUpdatedSelectedItemrecent-searches.stateChangeTypes.touchEndSee stateReducer for a concrete example on how to use the
type property.
recent-searches manages its own state internally and calls your onChange and
onStateChange handlers with any relevant changes. The state that recent-searches
manages includes: isOpen, selectedItem, inputValue, and
highlightedIndex. Your Children function (read more below) can be used to
manipulate this state and can likely support many of your use cases.
However, if more control is needed, you can pass any of these pieces of state as
a prop (as indicated above) and that state becomes controlled. As soon as
this.props[statePropKey] !== undefined, internally, recent-searches will determine
its state based on your prop's value rather than its own internal state. You
will be required to keep the state up to date (this is where onStateChange
comes in really handy), but you can also control the state from anywhere, be
that state from other components, redux, react-router, or anywhere else.
Note: This is very similar to how normal controlled components work elsewhere in react (like
<input />). If you want to learn more about this concept, you can learn about that from this the Advanced React Component Patterns course
This is where you render whatever you want to based on the state of recent-searches.
You use it like so:
const ui = (
<recent-searches>
{recent-searches => (
// use recent-searches utilities and state here, like recent-searches.isOpen,
// recent-searches.getInputProps, etc.
<div>{/* more jsx here */}</div>
)}
</recent-searches>
)
The properties of this recent-searches object can be split into three categories as
indicated below:
NOTE: These prop-getters provide important
aria-attributes which are very important to your component being accessible. It's recommended that you utilize these functions and apply the props they give you to your components.
These functions are used to apply props to the elements that you render. This
gives you maximum flexibility to render what, when, and wherever you like. You
call these on the element in question (for example: <input {...getInputProps()})). It's advisable to pass all your props to that function
rather than applying them on the element yourself to avoid your props being
overridden (or overriding the props returned). For example:
getInputProps({onKeyUp(event) {console.log(event)}}).
| property | type | description |
|---|---|---|
getToggleButtonProps |
function({}) |
returns the props you should apply to any menu toggle button element you render. |
getInputProps |
function({}) |
returns the props you should apply to the input element that you render. |
getItemProps |
function({}) |
returns the props you should apply to any menu item elements you render. |
getLabelProps |
function({}) |
returns the props you should apply to the label element that you render. |
getMenuProps |
function({},{}) |
returns the props you should apply to the ul element (or root of your menu) that you render. |
getRootProps |
function({},{}) |
returns the props you should apply to the root element that you render. It can be optional. |
getRootPropsMost of the time, you can just render a div yourself and recent-searches will
apply the props it needs to do its job (and you don't need to call this
function). However, if you're rendering a composite component (custom component)
as the root element, then you'll need to call getRootProps and apply that to
your root element (recent-searches will throw an error otherwise).
There are no required properties for this method.
Optional properties:
refKey: if you're rendering a composite component, that component will need
to accept a prop which it forwards to the root DOM element. Commonly, folks
call this innerRef. So you'd call: getRootProps({refKey: 'innerRef'}) and
your composite component would forward like: <div ref={props.innerRef} />If you're rendering a composite component, recent-searches checks that
getRootProps is called and that refKey is a prop of the returned composite
component. This is done to catch common causes of errors but, in some cases, the
check could fail even if the ref is correctly forwarded to the root DOM
component. In these cases, you can provide the object {suppressRefError : true} as the second argument to getRootProps to completely bypass the check.\
Please use it with extreme care and only if you are absolutely sure that the ref
is correctly forwarded otherwise recent-searches will unexpectedly fail.\
See #235 for the discussion that lead to this.
getInputPropsThis method should be applied to the input you render. It is recommended that
you pass all props as an object to this method which will compose together any
of the event handlers you need to apply to the input while preserving the ones
that recent-searches needs to apply to make the input behave.
There are no required properties for this method.
Optional properties:
disabled: If this is set to true, then no event handlers will be returned
from getInputProps and a disabled prop will be returned (effectively
disabling the input).getLabelPropsThis method should be applied to the label you render. It is useful for
ensuring that the for attribute on the <label> (htmlFor as a react prop)
is the same as the id that appears on the input. If no htmlFor is provided
(the normal case) then an ID will be generated and used for the input and the
label for attribute.
There are no required properties for this method.
Note: For accessibility purposes, calling this method is highly recommended.
getMenuPropsThis method should be applied to the element which contains your list of items.
Typically, this will be a <div> or a <ul> that surrounds a map expression.
This handles the proper ARIA roles and attributes.
Optional properties:
refKey: if you're rendering a composite component, that component will need
to accept a prop which it forwards to the root DOM element. Commonly, folks
call this innerRef. So you'd call: getMenuProps({refKey: 'innerRef'}) and
your composite component would forward like: <ul ref={props.innerRef} />.
However, if you are just rendering a primitive component like <div>, there
is no need to specify this property.
Please keep in mind that menus, for accessiblity purposes, should always be
rendered, regardless of whether you hide it or not. Otherwise, getMenuProps
may throw error if you unmount and remount the menu.
aria-label: By default the menu will add an aria-labelledby that refers
to the <label> rendered with getLabelProps. However, if you provide
aria-label to give a more specific label that describes the options
available, then aria-labelledby will not be provided and screen readers
can use your aria-label instead.
In some cases, you might want to completely bypass the refKey check. Then you
can provide the object {suppressRefError : true} as the second argument to
getMenuProps.
Please use it with extreme care and only if you are absolutely sure that the ref
is correctly forwarded otherwise recent-searches will unexpectedly fail.
<ul {...getMenuProps()}>
{!isOpen
? null
: items.map((item, index) => (
<li {...getItemProps({item, index, key: item.id})}>{item.name}</li>
))}
</ul>
Note that for accessibility reasons it's best if you always render this element whether or not recent-searches is in an
isOpenstate.
getItemPropsThe props returned from calling this function should be applied to any menu items you render.
This is an impure function, so it should only be called when you will actually be applying the props to an item.
Basically just don't do this:
items.map(item => {
const props = getItemProps({item}) // we're calling it here
if (!shouldRenderItem(item)) {
return null // but we're not using props, and recent-searches thinks we are...
}
return <div {...props} />
})
Instead, you could do this:
items.filter(shouldRenderItem).map(item => <div {...getItemProps({item})} />)
Required properties:
item: this is the item data that will be selected when the user selects a
particular item.Optional properties:
index: This is how recent-searches keeps track of your item when updating the
highlightedIndex as the user keys around. By default, recent-searches will
assume the index is the order in which you're calling getItemProps. This
is often good enough, but if you find odd behavior, try setting this
explicitly. It's probably best to be explicit about index when using a
windowing library like react-virtualized.disabled: If this is set to true, then all of the recent-searches item event
handlers will be omitted. Items will not be highlighted when hovered,
and items will not be selected when clicked.getToggleButtonPropsCall this and apply the returned props to a button. It allows you to toggle
the Menu component. You can definitely build something like this yourself (all
of the available APIs are exposed to you), but this is nice because it will also
apply all of the proper ARIA attributes.
Optional properties:
disabled: If this is set to true, then all of the recent-searches button event
handlers will be omitted (it wont toggle the menu when clicked).aria-label: The aria-label prop is in English. You should probably override
this yourself so you can provide translations:const myButton = (
<button
{...getToggleButtonProps({
'aria-label': translateWithId(isOpen ? 'close.menu' : 'open.menu'),
})}
/>
)
These are functions you can call to change the state of the recent-searches component.
| property | type | description |
|---|---|---|
clearSelection |
function(cb: Function) |
clears the selection |
clearItems |
function() |
Clears recent-searches's record of all the items. Only really useful if you render your items asynchronously within recent-searches. See #186 |
closeMenu |
function(cb: Function) |
closes the menu |
openMenu |
function(cb: Function) |
opens the menu |
selectHighlightedItem |
function(otherStateToSet: object, cb: Function) |
selects the item that is currently highlighted |
selectItem |
function(item: any, otherStateToSet: object, cb: Function) |
selects the given item |
selectItemAtIndex |
function(index: number, otherStateToSet: object, cb: Function) |
selects the item at the given index |
setHighlightedIndex |
function(index: number, otherStateToSet: object, cb: Function) |
call to set a new highlighted index |
toggleMenu |
function(otherStateToSet: object, cb: Function) |
toggle the menu open state |
reset |
function(otherStateToSet: object, cb: Function) |
this resets recent-searches's state to a reasonable default |
setItemCount |
function(count: number) |
this sets the itemCount. Handy in situations where you're using windowing and the items are loaded asynchronously from within recent-searches (so you can't use the itemCount prop. |
unsetItemCount |
function() |
this unsets the itemCount which means the item count will be calculated instead by the itemCount prop or based on how many times you call getItemProps. |
setState |
function(stateToSet: object, cb: Function) |
This is a general setState function. It uses recent-searches's internalSetState function which works with control props and calls your onSelect, onChange, etc. (Note, you can specify a type which you can reference in some other APIs like the stateReducer). |
otherStateToSetrefers to an object to set other internal state. It is recommended to avoid abusing this, but is available if you need it.
These are values that represent the current state of the recent-searches component.
| property | type | description |
|---|---|---|
highlightedIndex |
number / null |
the currently highlighted item |
inputValue |
string / null |
the current value of the getInputProps input |
isOpen |
boolean |
the menu open state |
selectedItem |
any |
the currently selected item input |
As a convenience, the id and itemToString props which you pass to
<recent-searches /> are available here as well.
recent-searches has a few events for which it provides implicit handlers. Several of
these handlers call event.preventDefault(). Their additional functionality is
described below.
ArrowDown: if menu is closed, opens it and moves the highlighted index to
defaultHighlightedIndex + 1, if defaultHighlightedIndex is provided, or
to the top-most item, if not. If menu is open, it moves the highlighted index
down by 1. If the shift key is held when this event fires, the highlighted
index will jump down 5 indices instead of 1. NOTE: if the current highlighed
index is within the bottom 5 indices, the top-most index will be highlighted.)
ArrowUp: if menu is closed, opens it and moves the highlighted index to
defaultHighlightedIndex - 1, if defaultHighlightedIndex is provided, or
to the bottom-most item, if not. If menu is open, moves the highlighted index
up by 1. If the shift key is held when this event fires, the highlighted
index will jump up 5 indices instead of 1. NOTE: if the current highlighed
index is within the top 5 indices, the bottom-most index will be highlighted.)
Home: if menu is closed, it will not add any other behavior. If menu is open,
the top-most index will get highlighted.
End: if menu is closed, it will not add any other behavior. If menu is open,
the bottom-most index will get highlighted.
Enter: if the menu is open, selects the currently highlighted item. If the menu
is open, the usual 'Enter' event is prevented by recent-searches's default implicit enter
handler; so, for example, a form submission event will not work as one might expect
(though if the menu is closed the form submission will work normally). See below
for customizing the handlers.
Escape: will reset recent-searches's state. This means that highlightedIndex will be
set to the defaultHighlightedIndex, the inputValue will be set to the itemToString
value of the selectedItem, and the isOpen state will be set to the defaultIsOpen.
You can provide your own event handlers to recent-searches which will be called before the default handlers:
const ui = (
<recent-searches>
{({getInputProps}) => (
<input
{...getInputProps({
onKeyDown: event => {
// your handler code
},
})}
/>
)}
</recent-searches>
)
If you would like to prevent the default handler behavior in some cases, you can set the event's preventrecent-searchesDefault property to true:
const ui = (
<recent-searches>
{({getInputProps}) => (
<input
{...getInputProps({
onKeyDown: event => {
if (event.key === 'Enter') {
// Prevent recent-searches's default 'Enter' behavior.
event.nativeEvent.preventrecent-searchesDefault = true
// your handler code
}
},
})}
/>
)}
</recent-searches>
)
If you would like to completely override recent-searches's behavior for a handler, in favor of your own, you can bypass prop getters:
const ui = (
<recent-searches>
{({getInputProps}) => (
<input
{...getInputProps()}
onKeyDown={event => {
// your handler code
}}
/>
)}
</recent-searches>
)
Allows reseting the internal id counter which is used to generate unique ids for recent-searches component.
You should never need to use this in the browser. Only if you are running an universal React app that is rendered on the server you should call resetIdCounter before every render so that the ids that get generated on the server match the ids generated in the browser.
import {resetIdCounter} from 'recent-searches';
resetIdCounter()
ReactDOMServer.renderToString(...);
Since recent-searches renders it's UI using render props, recent-searches supports rendering on React Native with ease. Use components like <View>, <Text>, <TouchableOpacity> and others inside of your render method to generate awesome autocomplete, dropdown, or selection components.
getRootProps or call getRootProps with { suppressRefError: true }. This ref is used to catch a common set of errors around composite components. Learn more in getRootProps.<FlatList> or <ScrollView>, be sure to supply the keyboardShouldPersistTaps prop to ensure that your text input stays focus, while allowing for taps on the touchables rendered for your items.Kent C. Dodds has created learning material based on the patterns implemented in this component. You can find it on various platforms:
π¨ We're in the process of moving all examples to the recent-searches-examples repo (which you can open, interact with, and contribute back to live on codesandbox)
Ordered Examples:
If you're just learning recent-searches, review these in order:
selectedItem so the selected item can be one of your items or whatever the user types.Other Examples:
Check out these examples of more advanced use/edge cases:
React.createContext and a recent-searches higher order component. This is generally not recommended because the render prop API exported by recent-searches is generally good enough for everyone, but there's nothing technically wrong with doing something like this.Old Examples exist on codesandbox.io:
π¨ This is a great contribution opportunity! These are examples that have not yet been migrated to recent-searches-examples. You're more than welcome to make PRs to the examples repository to move these examples over there. Watch this to learn how to contribute completely in the browser
react-instantsearch
from AlgoliaGenieJS
(learn more about genie here)react-tiny-virtual-listfuzzaldrin-plus (Fuzzy matching)withrecent-searches higher order component which you can use to get at
the state, actions, prop getters in a rendered recent-searches tree).redux-formreact-final-formThe checksum error you're seeing is most likely due to the automatically
generated id and/or htmlFor prop you get from getInputProps and
getLabelProps (respectively). It could also be from the automatically
generated id prop you get from getItemProps (though this is not likely as
you're probably not rendering any items when rendering a recent-searches component on
the server).
To avoid these problems, simply call resetIdCounter before
ReactDOM.renderToString.
Alternatively you could provide your own ids via the id props where you render
<recent-searches />:
const ui = (
<recent-searches
id="autocomplete"
labelId="autocomplete-label"
inputId="autocomplete-input"
menuId="autocomplete-menu"
>
{({getInputProps, getLabelProps}) => <div>{/* your UI */}</div>}
</recent-searches>
)
I was heavily inspired by Ryan Florence. Watch his (free) lesson about "Compound Components". Initially recent-searches was a group of compound components using context to communicate. But then Jared Forsyth suggested I expose functions (the prop getters) to get props to apply to the elements rendered. That bit of inspiration made a big impact on the flexibility and simplicity of this API.
I also took a few ideas from the code in
react-autocomplete and jQuery UI's
Autocomplete.
You can watch me build the first iteration of recent-searches on YouTube:
You'll find more recordings of me working on recent-searches on my livestream
YouTube playlist.
You can implement these other solutions using recent-searches, but if you'd prefer
to use these out of the box solutions, then that's fine too:
If you're developing some React in ReasonML, check out the recent-searches bindings for that.
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT
Generated using TypeDoc