This is a reaction timer package, ready to install and use directly in your project, made in a headless UI way (I love them), you can customize it using TailwindCSS and satisfy the design enthusiast.
import { ReactionTime, Analytics } from "./ReactionTimer";
import { useState } from "react";
function App() {
const [reactionTimeState, setReactionTimeState] = useState<number>(0);
return (
<>
<ReactionTime className='flex flex-col items-center w-full h-96' onReactionTimeChange={setReactionTimeState} instructionsClassName="text-2xl">
<p className="text-2xl font-black">{reactionTimeState}</p>
</ReactionTime>
<Analytics onReactionTimeChange={setReactionTimeState} height={300} className="w-[100vw]" />
</>
)
}
export default App
ReactionTime
is the component that can be imported and used for the functionality.
The reactionTimeOutput
is a required number-type state that needs to be declared manually which also serves as the output of the individual tests. At the same time, the setReactionTimeOutput
is the state function and must be defined inside the component.
waitTime
(number) optional: The time you would like the timer to stay red or wait for the click.className
(string) optional: The styling of the reaction time area, is strictly based on tailwind and can be treated as adiv
.needInstruction
(boolean) optional defaults totrue
: Control whether you need the instructions or not.instructionClassName
(string) optional: The styling of the instructions, is strictly based on tailwind.onReactionTimeChange
(state-function) optional: The state function of the declared state to feed in the changed values to the state.
The Analytics
is the component that can be imported and used for the Analysis of the Tests Taken.
The Analytics Graph
tracks the values of Average Reaction Time
, Best Reaction Time Scores
, and All Reaction Time Scores
Note:
localStorage
is used to store the Reaction Time Test data and hence should be used carefully and only on the client side.
className
(string) optional: The styling of the reaction time area, is strictly based on tailwind and can be treated as adiv
.height
(number) optional defaults tofull height
of theparent div
: The height of the graph object present inside the parent div.width
(number) optional defaults tofull width
of theparent div
: The width of the graph object present inside the parent div.onReactionTimeChange
(state-function) optional: The state function of the declared state to feed in the changed values to the state.