1.1.6 • Published 1 year ago

surf-timer v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Surf-Timer

MIT License

Description

Tracks consumed time in a page while considering idle time and user activity.

Installation

 # With yarn
yarn add surf-timer

# With npm
npm i surf-timer

Example Usage

import { useSurfTimer } from "surf-timer";

function App() {
  const surfTime = useSurfTimer({
    idleTime: 2000,
    initialState: false,
    intervalTime: 1000,
    fn() {
      console.log("hello world");
    },
  });

  useEffect(() => {
    surfTime.interval.start();
    return surfTime.interval.stop;
  }, []);

  return (
    <div>
      <h2>Current Idle State: {surfTime.idle ? "true" : "false"}</h2>
      <h2>
        Current Interval State: {surfTime.interval.active ? "Start" : "Stop"}
      </h2>
    </div>
  );
}

export default App;

Definition

ParametersDescription
idleTimeRefers to the duration seconds of user inactivity.
initialStateInitial state of idle (boolean)
intervalTimeAmount of milliseconds between each tick
fnFunction that is called at each interval tick
eventsEvents that hook will listen

Custom Events

By default, the hook will listen to keypress, mousemove, touchmove, click and scrollevents to set idle status.

Return Object

surfTime.idle -> current idle status

surfTime.interval.start -> start interval

surfTime.interval.stop -> stop interval

surfTime.interval.toggle -> toggle interval

surtTime.interval.active -> current interval status

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago