JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2047
  • Score
    100M100P100Q110312F
  • License ISC

React hook for handling parameters in URL fragment

Package Exports

  • use-hash-param

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-hash-param) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

useHashParam

Package version on NPM Build status Bundle size

React hook that allows to keep your state in sync with URL parameters.

Installation

npm install --save use-hash-param

Usage

import React from 'react';
import useHashParam from 'use-hash-param';

function ControlledInput() {
  const [name, setName] = useHashParam('name');

  return (
    <input value={name || ''} onChange={e => setName(e.target.value)} />
  );
);

Anything you type into the input will be reflected in the address bar (e.g. http://localhost:3000/#?name=Peter). And if you open a link with such a parameter, the field will be populated automatically!

Example