๐Ÿ“ useLocation

September 15, 2021 ยท View on GitHub

Read and manipulate window.location

Usage

import { useLocation } from 'react-recipes';

function App() {
  const { push, replace, pathname, search } = useLocation();

  return (
    <div>
      <div>
        <button onClick={() => push('/example')}>Push to /example</button>
      </div>
      <div>
        <button onClick={() => replace('/example?search=example2')}>Replace to /example?searchexample2</button>
      </div>
      <h3>Pathname: {pathname}</h3>
      <h3>Search: {search}</h3>
    </div>
  );
}