usestate
usestate gives the webcomponents a new life cycle.
It is effective when doing data binding.
$ npm i -S usestate
Usage
; /* ... */ Component
or
; @useState /* ... */
What can I do with it?
A component with usestate can use the following methods.
getState()
setState(object)
stateChangedCallback(stateName, oldValue, newValue)
static get observedState
stateChangedCallback()
is called when a state is changed. Only called for observed state. So stateChangedCallback()
is like attributeChangedCallback()
.
You can use setState()
to change a state. setState()
find the difference of state.
You should define the state to be observed by observedState()
method.
observedState()
method is a static getter method that returns an array of state names like observedAttributes()
.
example
{ super; const input = document; inputtype = 'text'; input { this; } this; thisp = document; this; } { } static { return 'name'; } customElements; const helloElement = new ;documentbody; helloElement;
With flux.
const dispatcher = ; { super; thisname = ''; dispatcher; }const store = { super; thishandleStoreChange = thishandleStoreChange; const input = document; inputtype = 'text'; input { dispatcher; } this; thisp = document; this; } { this; } { store; //initialization this; } { store; } { } static { return 'name'; } customElements; const helloElement = new ;documentbody;
License
ISC