0.2.0 • Published 3 years ago

react-state-ref v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

State Ref Hook

Do you have a token that changes but you need to know when it's unset? Do some states need to update effects only some times? Do you need something between useRef and useState?

Try useStateRef in React!

Installation

npm i react-state-ref

Methods

useStateRef

Like useState but the setState function can take a swap boolean.

const [ref, setState] = useStateRef('state1');

useEffect(() => {
	setTimeout(() => {
		setState('state2');
	}, 100);

	setTimeout(() => {
		setState('state3', true);
	}, 200);
}, []);

useEffect(() => {
	console.log(ref.current);
	// Outputs: 'state1', 'state3'
}, [ref])

License

Copyright (c) 2021, Michael Szmadzinski. (MIT License)

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago