Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 1.81 KB

File metadata and controls

55 lines (35 loc) · 1.81 KB

checks version GitHub top language license npm

ko-fi

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-constant

Or if you are using npm:

npm install @seaofvoices/react-lua-use-constant

Usage

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

Other 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.