Skip to content

Latest commit

Β 

History

History
39 lines (33 loc) Β· 658 Bytes

useQueryParams.md

File metadata and controls

39 lines (33 loc) Β· 658 Bytes

πŸ“ useQueryParams

Gets and sets query params

Usage

import { useQueryParams } from 'react-recipes';

function App() {
  const { getParams, setParams } = useQueryParams();

  const params = getParams();

  return (
    <div>
      <button
        onClick={() => {
          setParams({ page: 1, order: 'ASC' });
        }}
      >
        Set Params
      </button>
      <button
        onClick={() => {
          setParams({});
        }}
      >
        Clear params
      </button>
      {Object.entries(params).map(([paramKey, paramValue]) => (
        <p>
          {paramKey}: {paramValue}
        </p>
      ))}
    </div>
  );
}