Skip to content

Latest commit

Β 

History

History
26 lines (21 loc) Β· 548 Bytes

useLocation.md

File metadata and controls

26 lines (21 loc) Β· 548 Bytes

πŸ“ useLocation

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>
  );
}