-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
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.
- Why componentDidUpdate instead of shouldComponentUpdate ?
public async componentDidUpdate(prevProps: ImageProps) {
if (this.props.src === prevProps.src) {
return;
}
await this.renderImage();
}- 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" />;
}- If you really want to get best performance while loop on
lastChildis faster. ;)
while (this.container.firstChild) {
this.container.removeChild(this.container.firstChild);
}Metadata
Metadata
Assignees
Labels
No labels