Hooks
The Hooks module provides hooks similar to React.js for state and effect management.
Hooks.useState(initialValue) -> State
Parameters
- initialValue
- Type:
any
- Required:
Yes
- Description: Initial value for the state hook.
- Type:
Returns
- State
- Type:
State
- Always:
Yes
- Description: A new
State
object initialized with the given value.
- Type:
Description
Creates a new reactive state variable.
lua
local count = Vuxel.Hooks.useState(0)
Hooks.useEffect(state, callback) -> void
Parameters
- state
- Type:
State
- Required:
Yes
- Description: The
State
object to monitor for changes.
- Type:
- callback
- Type:
function
- Required:
Yes
- Description: The function to call when
state
changes.
- Type:
Returns
- void
- Type:
nil
- Always:
Yes
- Description: No return value; registers a callback that triggers when the state changes.
- Type:
Description
Executes the callback whenever the given state changes.
lua
Vuxel.Hooks.useEffect(count, function(newCount)
print("Count changed to", newCount)
end)