Skip to content

getState :function

function getState(Scope: Scope): (inputValue: CanBeState<any>, defaultValue: CanBeState<any>, mustBeKind: string?) -> CanBeState<any>

This utility function ensures that you get the correct Fusion object type at all costs.

  • If the input type is a State, and the mustBeKind is also set to "State", then the inputValue will be returned.
  • If the input type is a State, but the mustBeKind is set to something else, then the utility function will create a new object from the kind set in the mustBeKind, with the value from the inputValue, and return it.
  • If both of these are false, but the defaultValue is a State, then the defaultValue will be returned.
  • If all of the above are false, but the defaultValue still exists, then the utility function will create a new object from the kind either set in the mustBeKind, or the kind "Value" by default, with the value from the defaultValue and return it.

Default Syntax

local getStateUtility = require(StudioComponents.Util.getState)
local getState = getStateUtility(Scope)

Shorthand

local getState = require(StudioComponents.Util.getState)(Scope)

Parameters

Scope: Scope The Scope the utility function will be initialized in.

Returns Function

Parameters

inputValue: CanBeState<any> The input value to be checked.
defaultValue: CanBeState<any> If the input value is not provided or not valid, then this value will be used.
mustBeKind: string? This parameter ensures that the provided values must be a certain Fusion type.

Returns

CanBeState<any>