Skip to content

Instantly share code, notes, and snippets.

@tomasz-stefaniak
tomasz-stefaniak / useDynamicTextareaSize.ts
Created February 12, 2024 18:23
Custom hook for dynamically resizing a textarea to fit its content.
/**
* Custom hook for dynamically resizing a textarea to fit its content.
* @param {React.RefObject<HTMLTextAreaElement>} textareaRef - Reference to the textarea element.
* @param {string} textContent - Current text content of the textarea.
* @param {number} maxHeight - Optional: maxHeight of the textarea in pixels.
*/
import { useEffect } from "react";
export const useDynamicTextareaSize = (
@tomasz-stefaniak
tomasz-stefaniak / WithConfirmation.tsx
Created February 14, 2024 07:32
A wrapper component with a render prop for showing a confirmation message before button click
import React from "react";
// Usage:
// <WithConfirmation
// onClick={deletePost}
// confirmationMessage="Are you sure you want to delete this post?"
// renderButton={({ onClick }) => {
// return (
// <button onClick={onClick}>
// Delete post