neworbit / load-image-react Goto Github PK
View Code? Open in Web Editor NEWUse blueimp-load-image in React
License: MIT License
Use blueimp-load-image in React
License: MIT License
As I understand it, blueimp-load-image
simply renders an image on a canvas, but does not include a clickable link. This package is a way of using that package in React, but renders the image inside a clickable link to the image. Is that correct? Is there a reason for the two being different in this aspect? Thanks in advance.
This exception is happening inside image.js
and I'm wondering if it's due to the fact that my <Image>
element is conditionally-rendered? The image does end up loading properly, but I do see this error in the console.
image.js:257 Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
at Image.<anonymous> (image.js:257)
at step (image.js:151)
at Object.next (image.js:81)
at fulfilled (image.js:33)
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.
public async componentDidUpdate(prevProps: ImageProps) {
if (this.props.src === prevProps.src) {
return;
}
await this.renderImage();
}
React.createRef()
Right now each render creates new arrow function with ref, it's not a ideal for performance. public render() {
return <a ref={el => this.container = el} href={this.props.src} className="loaded-image-container" />;
}
lastChild
is faster. ;) while (this.container.firstChild) {
this.container.removeChild(this.container.firstChild);
}
I am having trouble figuring out how to display an image with a responsive size. I display images using the bootstrap grid system from react-bootstrap, and I can't figure out a way to have the image size scale with its parent container. The image canvas always has a fixed size, so when the browser is resized, the image either overflows its parent, or does not fill the entire space of its parent.
I have attempted to accomplish responsive width using refs
by reading the width of the parent into the state (and updating the state when the window resizes), and setting the maxWidth of Image to the state variable. However this doesn't work.
Do you have an suggestions as to how I could accomplish this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.