NoteThis hook uses Object.is for comparison. It only updates the "previous" reference when the current value actually changes, making it ideal for tracking props or IDs.
The usePreviousDistinct tracks a specific value and stores its inmediate predecessor, but only when the new value differs from the current one. It acts as a specialized memory buffer that ignores identical consecutive renders, ensuring that the returned previous value is always functionally different from the current value.
| Name | Type | Description |
|---|---|---|
| value | T Generic | The variable or state to track for distinct changes. |
| Name | Type | Description |
|---|---|---|
| previous | T Generic | undefined | The previous value of the tracked variable. |