• Custom React hook that creates a state that automatically synchronizes with an external value.

    This hook allows you to manage local state that reflects the value of a prop. When the prop changes, the internal state is updated to match the new prop value. This is useful when you want to have controlled components that also sync with their props.

    Example

    const MyComponent = ({ initialValue }) => {
    const [value, setValue] = usePropState(initialValue);

    return (
    <div>
    <p>Current Value: {value}</p>
    <button onClick={() => setValue(value + 1)}>Increment</button>
    </div>
    );
    };

    Type Parameters

    • T

    Parameters

    • prop: T

      The external value to synchronize with.

    Returns [T, Dispatch<SetStateAction<T>>]