All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hooks.search.ts Maven / Gradle / Ivy

There is a newer version: 0.80.3
Show newest version
import { useLocation } from 'react-router';

export const useSearchVariable = (key: string): string | null => { 
  const { search } = useLocation();

  return getVariableFromSearch(search, key) 
}

export function getSearchVariable(key: string): string | null {
  const hash  = window.location.hash
  const index = (hash || '').indexOf('?')

  if (index < 0)
    return null

  return getVariableFromSearch(hash.slice(index), key)
}

function getVariableFromSearch(search: string, key: string) {
  const parameters = new URLSearchParams(search);
  return parameters.get(key)  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy