I'm use state in this.state in constructor. how can i use immediately state after declaration?
constructor() {
super(...arguments);
this.state = {
client: null,
client1: this.state.client,
}
}
I'm use state in this.state in constructor. how can i use immediately state after declaration?
constructor() {
super(...arguments);
this.state = {
client: null,
client1: this.state.client,
}
}
You can have your state in an object outside the assignment itself and then assigning the state to that object modifying whatever data you may want:
constructor(props) {
super(props);
const state = { client: null }
this.state = { ...state, client1: state.client };
}
Check this one out: "this" inside object
you could do:
constructor() {
super(...arguments);
this.state = {
client: null,
}
this.state.client1 = this.state.client;
}
Even though, you could also assign null
to client1
, as @zmag mentioned, if you always assign null
to this.state.client