How do I use a new Image() in react

后端 未结 2 1050
慢半拍i
慢半拍i 2021-01-11 15:08

I am trying to keep an image from reloading when the state changes. The below image variable is passed into the props of a custom react component.
var img = new Image();

2条回答
  •  终归单人心
    2021-01-11 15:21

    I think what you're trying to do is create a new DOMNode of the Image variety and render that as a child of the

    . If that's right, you're doing something React isn't made to do. Two options:

    Option 1 (Best): Render the image tag in your React component template

    render: function() {
        return (
            
    ); }

    Option 2 (Not as good): Render the image as an HTML string entity

    renderHTML: function() {
        return {
            __html : ''
        }
    },
    
    render: function() {
        return (
            
    ); }

    Hope that helps!

提交回复
热议问题