Skip to content

Minor improvements suggestions  #4

@bartlomiejzuber

Description

@bartlomiejzuber

Hi @Jameskmonger , I've look at code and got few suggestions.
Please take a look at them. Don't know if contributes are welcome here so I would rather ask than making PR with those changes.

If you don't like them just close the issue.

  1. Why componentDidUpdate instead of shouldComponentUpdate ?
    public async componentDidUpdate(prevProps: ImageProps) {
        if (this.props.src === prevProps.src) {
            return;
        }

        await this.renderImage();
    }
  1. Wouldn't it be better to create ref inside constructor ? React.createRef() Right now each render creates new arrow function with ref, it's not a ideal for performance.
    The thing you used here is callback ref it's designed especially to pass it to inner components but here is vanilla DOM component not custom JSX component.
    public render() {
        return <a ref={el => this.container = el} href={this.props.src} className="loaded-image-container" />;
    }
  1. If you really want to get best performance while loop on lastChild is faster. ;)
        while (this.container.firstChild) {
            this.container.removeChild(this.container.firstChild);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions