Skip to content

Commit 8a2ac6c

Browse files
zielinskimzfacebook-github-bot
authored andcommitted
Add useHandle hook
Summary: This diff adds a `useHandle` hook which creates and caches the `Handle`. Reviewed By: astreet Differential Revision: D67899670 fbshipit-source-id: cb6f8a4a15967bd1f6dfd1f1254f1a8807121e5b
1 parent ad9f464 commit 8a2ac6c

File tree

1 file changed

+11
-0
lines changed
  • litho-core/src/main/java/com/facebook/litho

1 file changed

+11
-0
lines changed

litho-core/src/main/java/com/facebook/litho/Handle.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.facebook.litho
1818

19+
import com.facebook.litho.annotations.Hook
20+
1921
/**
2022
* Instances of this class are used to uniquely identify [Component]s for triggering external events
2123
* including showing a [LithoTooltip] or triggering an [com.facebook.litho.annotations.OnTrigger]
@@ -49,3 +51,12 @@ class Handle {
4951
this.mountedViewReference = mountedViewReference
5052
}
5153
}
54+
55+
/**
56+
* Returns a new, cached [Handle] instance if it hasn't already been provided or if the [inputs]
57+
* have changed since the previous invocation of this method.
58+
*/
59+
@Hook
60+
fun ComponentScope.useHandle(vararg inputs: Any?): Handle {
61+
return useCached(inputs) { Handle() }
62+
}

0 commit comments

Comments
 (0)