> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: setState()

## Article: setState()

## Article Link: https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/states/set-state.md

## Article Content:

<!-- Source: packages/public-editor-platform-sdk/src/element/index.ts in wix-private/editor-platform -->
# setState()

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

## Syntax

```ts
function setState(stateKey: string | null): Promise<void>
```

## Parameters

| Name | Type | Description |
| :---- | :---- | :---- |
| `stateKey` | string \| null | Key of the state to activate. Must match a key returned by [`getStateDefinitions()`](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/states/get-state-definitions.md). 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()`](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/data/set-data.md) instead.

## Returns

`Promise<void>`

## Example

```js
import { reactElements } from '@wix/editor';

await reactElements.setState('hover');

// Return to the default state.
await reactElements.setState(null);
```

## See also

- [getState()](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/states/get-state.md)
- [getStateDefinitions()](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/states/get-state-definitions.md)
- [setData()](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/data/set-data.md)
- [About the React Elements API](https://dev.wix.com/docs/sdk/host-modules/editor/react-elements/introduction.md)