diff --git a/src/Preview.js b/src/Preview.js index 6566bda8..061c121a 100644 --- a/src/Preview.js +++ b/src/Preview.js @@ -3,10 +3,12 @@ import React, { Component } from 'react' const ICON_SIZE = '64px' export default class Preview extends Component { + mounted = false state = { image: null } componentDidMount () { + this.mounted = true this.fetchImage(this.props) } componentWillReceiveProps (nextProps) { @@ -14,6 +16,9 @@ export default class Preview extends Component { this.fetchImage(nextProps) } } + componentWillUnmount () { + this.mounted = false + } fetchImage ({ url, light }) { if (typeof light === 'string') { this.setState({ image: light }) @@ -23,7 +28,7 @@ export default class Preview extends Component { return window.fetch(`https://noembed.com/embed?url=${url}`) .then(response => response.json()) .then(data => { - if (data.thumbnail_url) { + if (data.thumbnail_url && this.mounted) { const image = data.thumbnail_url.replace('height=100', 'height=480') this.setState({ image }) }