I'm pretty new with React and this is what i'm trying to accomplish:
I want to show a large image that takes 3-4 seconds to load, so i want to show user a loader, which is achievable using ReactImage from https://www.npmjs.com/package/react-image
Then i want to add an option to zoom, but the zoom function should only be available after the image is loaded successfully, so i'm planning to use https://www.npmjs.com/package/react-image-magnify
However there's no events or possible way to make the 2 communicate their states with each other so that in my render()
function i can choose to use either ReactImage or ReactImageMagnify.
Any help would be appreciated.
Here is some pseudocode, i have a react component called Preview
, and it has a render()
function that returns either ReactImage or ReactImageMagnify
export class Preview extends React.Component {
...
render() {
...
// if image is not yet loaded then return ReactImage
return(
<ReactImage
src={this.getPreviewUrl()}
className=""
style={{ zIndex: 1 }}
alt=""
loader={<LoadingImage />}
/>
)
//if not, return ReactImageMagnify
return(
<ReactImageMagnify {...{
smallImage: {
alt: 'Chef Works',
isFluidWidth: true,
src: 'smallimage.png'
},
bigImage: {
alt: 'Chef Works',
isFluidWidth: true,
src: 'bigimage.png'
}
}}/>
)
}
}