Package Exports
- @seaofvoices/react-lua-use-constant
- @seaofvoices/react-lua-use-constant/src/init.lua
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@seaofvoices/react-lua-use-constant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-lua-use-constant
A react-lua hook to create a value once. It is different from useMemo, which can potentially re-calculate its value.
Installation
Add react-lua-use-constant in your dependencies:
yarn add @seaofvoices/react-lua-use-constantOr if you are using npm:
npm install @seaofvoices/react-lua-use-constantUsage
This hook takes an initializer function that gets called once to obtain the constant value.
local useConstant = require('@pkg/@seaofvoices/react-lua-use-constant')
local function Component(props)
local mountTime = useConstant(function()
return os.time()
end)
return ...
endOther Lua Environments Support
If you would like to use this library on a Lua environment, where it is currently incompatible, open an issue (or comment on an existing one) to request the appropriate modifications.
The library uses darklua to process its code.
License
This project is available under the MIT license. See LICENSE.txt for details.