rsnext/examples/with-algolia-react-instantsearch/utils/index.ts
Max Proske 994089fcc2
Improve with-algolia-react-instantsearch example and convert to TypeScript (#42617)
Converted to TypeScript to match Contribution docs, and updated/simplified the example.

- Replaced stylesheets in Head component with imported styles
- Removed `style-loader`, `css-loader`, `cross-env`, `prop-types` packages
- Removed custom webpack config

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm build && pnpm lint`
- [X] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-14 12:30:57 +00:00

10 lines
427 B
TypeScript

import type { SearchState } from 'react-instantsearch-core'
import qs from 'qs'
export const createURL = (state: SearchState) => `?${qs.stringify(state)}`
export const pathToSearchState = (path: string) =>
path.includes('?') ? qs.parse(path.substring(path.indexOf('?') + 1)) : {}
export const searchStateToURL = (searchState: SearchState) =>
searchState ? `${window.location.pathname}?${qs.stringify(searchState)}` : ''