Coder Social home page Coder Social logo

load-image-react's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar jameskmonger avatar ksstott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

load-image-react's Issues

Is there a way to load the image without the <a/> link element?

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.

TypeError: Cannot read property 'appendChild' of null

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) 

Minor improvements suggestions

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.

  1. Why componentDidUpdate instead of shouldComponentUpdate ?
    public async componentDidUpdate(prevProps: ImageProps) {
        if (this.props.src === prevProps.src) {
            return;
        }

        await this.renderImage();
    }
  1. 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" />;
    }
  1. If you really want to get best performance while loop on lastChild is faster. ;)
        while (this.container.firstChild) {
            this.container.removeChild(this.container.firstChild);
        }

Responsive Images

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.