You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason is that const state is sent to this.state in the component init().
However the toggle() function will always refer to the state that was declared, not from the copy of state from within the component.
A solution is to refer this.state from the component to the const state by reference (default in JS).
However this has as drawback: all instances of the component will share the same state.
State by reference: this.state = state
State by copy: this.state = Object.assign({}, state)
The text was updated successfully, but these errors were encountered:
Not sure to fully understand the issue, but if it ends to a this. use as with the extend syntax, then I would prefer the extend syntax as it is explicit that the this. refers to the class extending the Lego class. Less magic, so easier to understand.
The following example will toggle only once:
The reason is that
const state
is sent tothis.state
in the componentinit()
.However the
toggle()
function will always refer to thestate
that was declared, not from the copy ofstate
from within the component.A solution is to refer
this.state
from the component to theconst state
by reference (default in JS).However this has as drawback: all instances of the component will share the same state.
this.state = state
this.state = Object.assign({}, state)
The text was updated successfully, but these errors were encountered: