Lumen.State libraryclient
Part of Lumen
State for Lumen components. A component is a function of its props; the hooks in this file,
called while it renders, give it memory that survives between renders. They must be called
in the same order on every render, so they do not belong in conditions or loops. Templates
have them in scope as use_state, use_effect, use_ref and use_memo.
return function(props)
local count, set_count = use_state(0)
use_effect(function()
print('The count is now '..count)
end, { count })
return <button on_press={function() set_count(count + 1) end}>
Clicked {count} times
</button>
end
Summary
Functions
begin(instance)client
Starts a render of a component: the hooks that follow belong to this instance.
cleanup(instance)client
Runs the cleanups of the effects of an instance, when it is unmounted.
current()client
Returns the instance that is rendering.
finish()client
Ends the render that
begin started.run_effect(slot)client
Runs an effect whose dependencies have changed: its previous cleanup first, then the effect, keeping whatever it returns as the next cleanup.
Functions
Starts a render of a component: the hooks that follow belong to this instance.
Parameters
- instance Map instance of the component, as the reconciler keeps it
Runs the cleanups of the effects of an instance, when it is unmounted.
Parameters
- instance Map instance of the component
Returns the instance that is rendering.
Returns
- Map the instance, or nil outside of a render
Ends the render that begin started.
Runs an effect whose dependencies have changed: its previous cleanup first, then the effect, keeping whatever it returns as the next cleanup.
Parameters
- slot Map the hook slot of the effect