A react-lua hook to create a value once. It is different from useMemo, which can potentially re-calculate its value.
Add react-lua-use-constant
in your dependencies:
yarn add @seaofvoices/react-lua-use-constant
Or if you are using npm
:
npm install @seaofvoices/react-lua-use-constant
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 ...
end
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.
This project is available under the MIT license. See LICENSE.txt for details.