#29StateMedium

useGetSetState

useGetSetState

A mix of useGetSet and useGetSetState.

Usage

import {useGetSetState} from 'react-use';

const Demo = () => {
  const [get, setState] = useGetSetState({cnt: 0});
  const onClick = () => {
    setTimeout(() => {
      setState({cnt: get().cnt + 1})
    }, 1000);
  };

  return (
    <button onClick={onClick}>Clicked: {get().cnt}</button>
  );
};
// TODO: implement useGetSetState
function notImplemented(..._args: any[]): any {
  throw new Error('Not implemented');
}
export default notImplemented;
export const useGetSetState = notImplemented;

Open browser consoleTests