mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Directory Restructuring: - qml/qml-components/qml-components/* → qml/components/ (flattens nesting) - All 104 QML files moved with git history preserved - Eliminates redundant qml-components nesting Documentation Updates: - ARCHITECTURE.md: Updated qml/components references (2 locations) - GETTING_STARTED.md: Updated qml/components path (1 location, end of file) - README.md: Updated qml/components references (3 locations) - CODE_REVIEW.md: Updated qml/components file paths (4 locations) - docs/ARCHITECTURE.md: Complete refactor with qml/components paths Verification: - ✅ No remaining qml-components/ references in documentation - ✅ All 104 QML files present in flattened structure - ✅ Directory structure verified (12 component categories) - ✅ First-class directory naming convention Structure Post-Refactor: qml/ ├── components/ │ ├── atoms/ (16 files) │ ├── core/ (11 files) │ ├── data-display/ (10 files) │ ├── feedback/ (11 files) │ ├── form/ (19 files) │ ├── lab/ (11 files) │ ├── layout/ (12 files) │ ├── navigation/ (12 files) │ ├── surfaces/ (7 files) │ ├── theming/ (4 files) │ └── utils/ (13 files) ├── hybrid/ └── widgets/ Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
/**
|
|
* usePrevious Hook
|
|
* Track the previous value of any state or prop
|
|
*
|
|
* Features:
|
|
* - Generic typing for any value type
|
|
* - Tracks previous value across renders
|
|
* - Updated on every render with new value
|
|
* - Useful for comparing current vs previous values
|
|
* - Works with any data type (primitives, objects, arrays)
|
|
*
|
|
* @example
|
|
* const [count, setCount] = useState(0)
|
|
* const prevCount = usePrevious(count)
|
|
*
|
|
* <div>
|
|
* <p>Current: {count}</p>
|
|
* <p>Previous: {prevCount ?? 'N/A'}</p>
|
|
* <Button onClick={() => setCount(count + 1)}>Increment</Button>
|
|
* </div>
|
|
*
|
|
* @example
|
|
* // With objects
|
|
* const [user, setUser] = useState({ name: '', age: 0 })
|
|
* const prevUser = usePrevious(user)
|
|
*
|
|
* // Detect if user changed
|
|
* useEffect(() => {
|
|
* if (prevUser?.name !== user.name) {
|
|
* console.log('Name changed!')
|
|
* }
|
|
* }, [user, prevUser])
|
|
*
|
|
* @example
|
|
* // With form inputs - detect if value was actually changed
|
|
* const [email, setEmail] = useState('')
|
|
* const prevEmail = usePrevious(email)
|
|
*
|
|
* const hasChanged = prevEmail !== undefined && email !== prevEmail
|
|
*/
|
|
|
|
import { useEffect, useRef } from 'react'
|
|
|
|
/**
|
|
* Hook to track the previous value of any state or prop
|
|
* @template T - The type of the value being tracked
|
|
* @param value - Current value to track
|
|
* @returns Previous value (undefined on first render)
|
|
*/
|
|
export function usePrevious<T>(value: T): T | undefined {
|
|
const ref = useRef<T | undefined>(undefined)
|
|
|
|
useEffect(() => {
|
|
ref.current = value
|
|
}, [value])
|
|
|
|
return ref.current
|
|
}
|