Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 1.13 KB

index.en-US.md

File metadata and controls

61 lines (46 loc) · 1.13 KB

useUrlParams

A hook that return url param or calculated value from it.

Examples

Default usage

import React from 'react';
import { useUrlParams } from '@vergiss/chooks';

export default () => {
  const sourecFrom = useUrlParams('source-from');

  return (
    <span>
      { sourceFrom }
    </span>
  )
}

Advanced usage

import React from 'react';
import { useUrlParams } from '@vergiss/chooks';

export default () => {
  const isFromIndex = useUrlParmas('source-from', sourceFrom => sourceFrom === 'index');

  return (
    <span>
      { isFromIndex ? 'yes': 'no' }
    </span>
  )
}

API

const value = useUrlParams(
  paramName: string
)
const calculatedValue = useUrlParams(
  paramName: string,
  calculator: (value: any) => any
)

Params

Property Description Type Default
paramName Necessary string -
calculator Optional, a calculator function function -