Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Added usePlugin hook
- Added RectSize, RectOffset, and ResampleMode to icon props available in Button, MainButton, and Dropdown

## 1.1.0
Expand Down
2 changes: 1 addition & 1 deletion moonwave.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ classes = ["Background", "Button", "Checkbox", "ColorPicker", "DatePicker", "Dro
[[classOrder]]
section = "Hooks"
collapsed = false
classes = ["useMouseIcon", "useTheme"]
classes = ["useMouseIcon", "useTheme", "usePlugin"]
25 changes: 25 additions & 0 deletions src/Hooks/usePlugin.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--[=[
@class usePlugin

A hook used to obtain a reference to the root [plugin](https://create.roblox.com/docs/reference/engine/classes/Plugin)
instance associated with the current plugin. It requires a single [PluginProvider] to be present
higher up in the tree.

```lua
local function MyComponent()
local plugin = usePlugin()
...
end
```
]=]

local React = require("@pkg/@jsdotlua/react")

local PluginContext = require("../Contexts/PluginContext")

local function usePlugin()
local pluginContext = React.useContext(PluginContext)
return pluginContext and pluginContext.plugin
end

return usePlugin
1 change: 1 addition & 0 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ return {
ThemeContext = require("./Contexts/ThemeContext"),

useTheme = require("./Hooks/useTheme"),
usePlugin = require("./Hooks/usePlugin"),
useMouseIcon = require("./Hooks/useMouseIcon"),
}
Loading