Skip to content

useState

Import

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

Usage

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

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(
BoltElement
useState({
IDLE: true, SAVING: false, SAVED: false, ERROR: false
})
) {
doSomething() {
this.IDLE; // => true
}
}

Mutate the state

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

Dynamic Attributes

<stateName> : boolean

STATE : string