Files
react-native-fast-image/ReactNativeFastImageExample/src/withCacheBust.js
T
Dylan Vann 6994606073 chore: Update example to React Native 0.61.5. (#639)
This also upgrades all the dependencies.
2020-03-01 15:58:28 -05:00

30 lines
756 B
JavaScript

import React, { Component } from 'react'
import { v4 as uuid } from 'uuid'
export default BaseComponent => {
class WithCacheBust extends Component {
state = { bust: '?bust' }
onPressReload = () => {
// Force complete re-render and bust image cache.
const key = uuid()
const bust = `?bust=${key}`
this.setState({ bust })
}
render() {
return (
<BaseComponent
bust={this.state.bust}
onPressReload={this.onPressReload}
/>
)
}
}
WithCacheBust.displayName = `withCacheBust(${BaseComponent.displayName ||
BaseComponent.name})`
return WithCacheBust
}