An approach to testing stateful React components
Testing stateful React components is not difficult, but did you know there's a solution that doesn't involve testing state directly?
The React snippet collection contains function components and reusable hooks for React 18.
Testing stateful React components is not difficult, but did you know there's a solution that doesn't involve testing state directly?
Adds an event listener for the specified event type on the given element.
Creates a stateful value, and a function to update it by merging the new state provided.
Creates a portal, allowing rendering of children outside the parent component.
Renders a spinning loader component.
Executes a callback whenever the window is resized.
Creates a stateful value that is persisted to localStorage
, and a function to update it.
Checks if the client is online or offline.
Creates a stateful value that is persisted to sessionStorage
, and a function to update it.
Handles the beforeunload
window event.
Renders a list of elements from an array of primitives.
Renders a component with collapsible content.
Renders a controlled <input>
element that uses a callback function to inform its parent about value updates.
Renders a textarea component with a character limit.
Debounces the given value.
Creates a stateful value from the fields in a form.
Observes visibility changes for a given element.
Renders a string as plaintext, with URLs converted to appropriate link elements.
In React components, you might need to conditionally apply a className
. Learn how to handle empty values correctly using this handy tip.
Copies the given text to the clipboard.
Checks if the current environment matches a given media query and returns the appropriate value.
Implements setTimeout()
in a declarative manner.
Learn of all the different ways to set the value of a selected input in React with this quick guide.
Creates an error dispatcher.