setState()

Sets the active state of the selected component, so you can preview it on the canvas from your panel.

Syntax

Copy

Parameters

NameTypeDescription
stateKeystring | nullKey of the state to activate. Must match a key returned by getStateDefinitions(). Pass null to return to the default state.

Note: For a state without a pseudoClass, setState() only changes what a Wix user sees while editing in the editor. It has no effect on the live site. If you need a toggle that persists for site visitors, store it in a data field with setData() instead.

Returns

Promise<void>

Example

Copy

See also

Last updated: 8 September 2026

Did this help?