Skip to main content

StateManagerVisibility

Deprecation notice

This is not a reliable way to hide sensitive values.

While this works for React Dev Tools, the built-in memory inspector in most browsers will still be able to show the value anyway. Please consider storing sensitive information on the server and only expose what's absolutely necessary to the client instead.

Starting from version 1.1.0, this option will be completely ignored.

Overview

Type: enum

This only concerns React for the time being.

This is used to control whether state values will be exposed in the React Developer Tools but only applies to StateManager and AsyncStateManager.


This can be specified in the options parameter in the constructor of the State Manager:

import { StateManager, StateManagerVisibility } from 'cotton-box'

const ExampleState = new StateManager('Hello, world!', {
visibility: StateManagerVisibility.HIDDEN,
})

Values

KeyValueDescription
ENVIRONMENT0State values will be exposed in non-production environments, but hidden in production environment.
EXPOSED1State values will be always exposed regardless of the environment.
HIDDEN2State values will be always hidden regardless of the environment.

The screenshots below show how State Managers with different visibility values appear in the React Developer Tools.

With StateManagerVisibility.HIDDEN:Inspecting an exposed state in React Dev ToolsInspecting an exposed state in React Dev Tools
With StateManagerVisibility.EXPOSED:Inspecting a hidden state in React Dev ToolsInspecting a hidden state in React Dev Tools