Skip to content

useState

Import

import { mix, useState, BoltElement } from 'c/bolt';

Usage

export default class myLwc extends mix(
[useState, states],
BoltElement
) { }

Methods

Constructor(states) : Constructor

State name whose value is true is the default state.

NameTypeDescription
states{[stateName]: boolean} OR {[stateNameSpace]:{[stateName]:boolean}}List of imported fields

Example

export default class myLwc extends mix(
[useSObject, {
IDLE: true, SAVING: false, SAVED: false, ERROR: false
}],
BoltElement
) {
doSomething() {
this.IDLE; // => true
}
}

Mutate the state

export default class myLwc extends mix(
[useSObject, {
IDLE: true, SAVING: false, SAVED: false, ERROR: false
}],
BoltElement
) {
doSomething() {
this.SAVING = true; // this.STATE = 'SAVING'
}
}

Dynamic Attributes

<stateName> : boolean

STATE : string