1.1.2 • Published 11 months ago

@kevinangkajaya/use-url-search-params v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Use URL Search Params

Introduction

Only for NextJS! Custom hook using UrlSearchParams to automate link given in the url. For example, when you are changing <input type="text" id="name" value="John" />, the result would appear in url (http://localhost?name=John)

Installing as a package

npm install @kevinangkajaya/use-url-search-params

Usage

import initUrlSearchParam from '@kevinangkajaya/use-url-search-params';
import { useRouter } from 'next/router';

const router = useRouter()
const initialValue = ""
const urlSearchParamKey = "name"
const giveDelay = true

const useUrlSearchParam = initUrlSearchParam(router)

const [name, set_name] = useUrlSearchParam(initialValue, urlSearchParamKey, giveDelay)

return(
    <input type="search" id="name" className="form-control" value={name}
        title="Search name" placeholder="Search name"
        onChange={(e) => set_name(e.target.value)} />
)

Props initUrlSearchParam

NameValueDefaultDescription
routerNextJsRouternullYou need to pass an instance of router (from useRouter) to this variable

Props useUrlSearchParam

NameValueDefaultDescription
initialValuestring""inital value of the state
urlSearchParamKeystring""Key name on the url params
giveDelayboolfalseGive delay when changing url params. Useful when changing state may be too fast.

Return Value initUrlSearchParam

Closure function to call useUrlSearchParam

Return Value useUrlSearchParam

ReactJS Custom Hook

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.1

11 months ago

0.0.1

11 months ago