useMouseIcon
A hook used internally by components for setting and clearing custom mouse icons. To use this hook, you need to also render a single PluginProvider somewhere higher up in the tree.
To set the mouse icon, use the setIcon
function and pass an asset url. All components under
the PluginProvider that use this hook share an icon stack; the most recent component to call
setIcon
will have its icon set as the final mouse icon. Calling setIcon
twice without
clearing it in between will override the previous icon set by this component.
Calling clearIcon
removes the icon set by this component from the stack, which may mean the
mouse icon falls back to the next icon on the stack set by another component. Ensure you call
clearIcon
on unmount otherwise your icon may never get unset. For example:
local function MyComponent()
local mouseIconApi = useMouseIcon()
React.useEffect(function() -- clear icon on unmount
return function()
mouseIconApi.clearIcon()
end
end, {})
return React.createElement(SomeComponent, {
OnHoverStart = function()
mouseIconApi.setIcon(...) -- some icon for hover
end,
OnHoverEnd = function()
mouseIconApi.clearIcon()
end
})
end
Types
mouseIconApi
interface
mouseIconApi {
setIcon:
(
icon:
string
)
→
(
)
getIcon:
(
)
→
string?
clearIcon:
(
)
→
(
)
}