M
M
Maxim Korolsky2016-06-12 19:35:30
JavaScript
Maxim Korolsky, 2016-06-12 19:35:30

How to optimize this feature?

setAvatarState(image) {
    if(image) {
      this.setState({
        avatars: image
      });
    }
    this.setState({
      imageUploadIsOpen: !this.state.imageUploadIsOpen
    });
  }

She looks bulky to me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Ninja Mate, 2016-06-12
@victorzadorozhnyy

setAvatarState(image) {
    this.setState({ avatars: image }, ()=>this.setState({ imageUploadIsOpen: !this.state.imageUploadIsOpen )}
}

it makes no sense)

M
Maxim Solovyov, 2017-04-21
@maxsolovev

Accidentally came here again and decided to answer, suddenly needed for the future.

setAvatarState(image) {
  const obj = {
    imageUploadIsOpen: !this.state.imageUploadIsOpen
  }
  if (image) obj['avatars'] = image
  this.setState(obj);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question