mardi 1 août 2017

Cleaner way of writing multiple conditional statements

I need to ask if you guys can find a much cleaner way of rewriting this code. I can't see to make it possible

Update

 const uploadedFiles = images.map((item, index) => {
  const imageContainer = <ImageContainer
      src={item.blobUrl}
      key={index}
      id={index}
      onClose={this.props.removeImage}
    />;

  if (images.length < 2 && item.file.name.match(/.(gif)$/i)) {
    return (
      <ImageGif
        key= {index}
        src= {item.blobUrl}
        onClose={this.props.removeImage}
      />
    );
  } else if (images.length < 2) {
    return { imageContainer };
  } else if (images.length >= 2) {
    if (MAX_SIZE === index + 1) {
      return (<ImageContainer
          src={item.blobUrl}
          key={index}
          id={index}
          onClose={this.props.removeImage}
          hiddenImages={hiddenImages}
        />);
    }
    if (MAX_SIZE !== index + 1) {
      return { imageContainer };
    }
  }

  return null;
});

Would really appreciate any directions. Have a good day.

Aucun commentaire:

Enregistrer un commentaire