Skip to content

Commit

Permalink
Add useHandle hook
Browse files Browse the repository at this point in the history
Summary: This diff adds a `useHandle` hook which creates and caches the `Handle`.

Reviewed By: astreet

Differential Revision: D67899670

fbshipit-source-id: cb6f8a4a15967bd1f6dfd1f1254f1a8807121e5b
  • Loading branch information
zielinskimz authored and facebook-github-bot committed Jan 7, 2025
1 parent ad9f464 commit 8a2ac6c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/Handle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.facebook.litho

import com.facebook.litho.annotations.Hook

/**
* Instances of this class are used to uniquely identify [Component]s for triggering external events
* including showing a [LithoTooltip] or triggering an [com.facebook.litho.annotations.OnTrigger]
Expand Down Expand Up @@ -49,3 +51,12 @@ class Handle {
this.mountedViewReference = mountedViewReference
}
}

/**
* Returns a new, cached [Handle] instance if it hasn't already been provided or if the [inputs]
* have changed since the previous invocation of this method.
*/
@Hook
fun ComponentScope.useHandle(vararg inputs: Any?): Handle {
return useCached(inputs) { Handle() }
}

0 comments on commit 8a2ac6c

Please sign in to comment.