# State and events

Understand visibility, preference drafts and committed choices.

Source: https://docs.peax.co/consent/concepts/state



## Three separate states [#three-separate-states]

| State             | Owner            | Meaning                                           |
| ----------------- | ---------------- | ------------------------------------------------- |
| `isOpen`          | Your application | Whether the banner is visible                     |
| Preferences draft | Banner           | Uncommitted edits while preferences are open      |
| Saved choices     | Your application | The decision used for persistence and enforcement |

Opening preferences initializes a draft from the selected sections. Editing an enabled switch emits `on_change_preference`. That message describes a draft, not a consent decision.

Apply emits all selected section IDs in `preferences`, including disabled sections. Your application commits the values, updates the supplied `checked` overrides and changes `isOpen` to `false`.

## Closing and reopening [#closing-and-reopening]

Close or Escape discards the draft and returns to the collapsed banner when preferences were opened from the banner. For floating-button sessions, handle `on_close_preferences` with `source: 'floating-button'` by setting `isOpen={false}`. Dismissal never grants consent. Setting `isOpen={false}` externally also discards the draft, without emitting a navigation message.

The floating button appears while the banner is closed. Handle `on_open_preferences` with `source: 'floating-button'` by setting `isOpen={true}` to open preferences directly. The [complete wrapper](/consent/quickstart) demonstrates an alternative application-owned Cookie choices button and disables the floating button.

## Updating sections [#updating-sections]

Rerenders retain edits for surviving enabled IDs. New IDs use their resolved defaults, removed IDs disappear, and disabled sections retain their resolved value. Changes to an existing enabled section's initial `checked` value apply on the next opening.

Keep configuration stable while a visitor is editing. See the [event reference](/consent/reference/events) for every message.
