@empathyco/x-components
Version:
Empathy X Components
57 lines (39 loc) • 1.82 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [HistoryQueriesActions](./x-components.historyqueriesactions.md) > [addQueryToHistory](./x-components.historyqueriesactions.addquerytohistory.md)
## HistoryQueriesActions.addQueryToHistory property
Saves a query to the history, synchronizing it with the browser storage. There are 3 possible cases.
**Signature:**
```typescript
addQueryToHistory: (query: string) => void;
```
## Example 1
When the query is totally new, it is simply added to the first position of the history.
```ts
const = historyQueries ['pork', 'cow'];
addQueryToHistory('goat');
// historyQueries is now ['goat', 'pork', 'cow'];
```
```ts
const = historyQueries ['pork', 'cow'];
addQueryToHistory('iberic pork');
// historyQueries is now ['iberic pork', 'pork', 'cow'];
```
## Example 2
When the normalized query equals other one contained in the history or one of its words is more specific, the old one is removed, and the new one is added to the first position of the array. We use the space and dash characters as delimiters for detecting individual words.
```ts
const = historyQueries ['tomahack', 'new york st'];
addQueryToHistory('new york strip');
// historyQueries is now ['new york strip', 'tomahack'];
```
```ts
const = historyQueries ['tomahack', 'new york strip'];
addQueryToHistory('new york strip');
// historyQueries is now ['new york strip', 'tomahack'];
```
## Example 3
When the query is less specific than the last query, it is not added.
```ts
const = historyQueries ['new york strip', 'tomahack'];
addQueryToHistory('new york st');
// historyQueries is now ['new york strip', 'tomahack'];
```