react-use-state-url-params
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

react-use-state-url-params

Travis npm package Coveralls

Installation

yarn add react-use-state-url-params

Demo

Usage

import useStateWithUrlParams from '../../src'

const Demo = (props) => {
	const [divColor, setDivColor] = useStateWithUrlParams('yellow', 'c');

	const getRandomClr = () => {
		const randomColor = Math.floor(Math.random() * 16777215).toString(16);
		return "#" + randomColor;
	}

	return <div>
		<h1>react-use-state-url-params Demo</h1>
		<div>
			<div
				onClick={() => {
					setDivColor(getRandomClr());
				}}
				style={{
					width: '400px',
					height: '400px',
					display: 'flex',
					justifyContent: 'center',
					alignItems: 'center',
					fontWeight: 'bold',
					fontSize: 'larger',
					backgroundColor: divColor
				}}>
				Click here to change the div color.
				</div>

		</div>
		<h3>Color value will be retained even on page refresh as state is synced with the URL params.</h3>
	</div>

}

References

Package Sidebar

Install

npm i react-use-state-url-params

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

20.5 kB

Total Files

9

Last publish

Collaborators

  • appwrk