React.js Code Snippets
Auth / User Provider and Hook
A context provider and consuming hook that manage polling for user login status. This is useful for any app that has any semblance of authentication.
useKeysPressed Hook
A React hook detecting whether at least one of a provided set of keys is pressed. Accepts an array of strings each representing a KeyBoardEvent's key
value. Returns a boolean: true
if one of them is pressed, false
if not.
useKeyPress Hook
A React hook detecting whether a key is pressed. Accepts a string representing a KeyBoardEvent's key
value. Returns a boolean: true
if it's pressed, false
if not.
usePageVisible Hook
A React hook using the Page Visibility API to determine whether the current tab is active / in focus.
useDarkMode Hook
A React hook for tracking and detecting the browser dark mode state. Always returns a boolean indicating whether the device is in dark mode true
in dark mode, false
when not.
useDeviceSize Hook
A React hook for tracking and retrieving the device size. Always returns a string indicating the current device size (sm
, md
, lg
, etc).
Simple Scatter Plot
Plot some points on a chart and color them in.
Simple Line Chart
Make a line chart from with domain 0 to 1 and range from ymin to ymax. With red line.
Line Chart with Custom Domain
In case you want to see more than just x at the interval [0, 1]. See the implementation of the range() function.
Line Chart for Parametric Functions
For when x and y values are dependent on a third value. See the implementation of the range() function.