DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/react-image-fallback package

8.0.0 • Public • Published

React Image Fallback

React Image Fallback exists for those times that you're just not sure an image will be there. See a simple demo here

Circle CI


npm install react-image-fallback

Required Props


A string represent the url to your primary image.


A string representing the image you want to fallback to if your primary image is not there. Optionally this can also be passed in as a react element. This can also be passed in as an array of string srcs or react elements, the component will attempt to keep trying srcs until a loadable src is found. It should be noted that a react element will always be treated as a loadable src.

Optional Props


The image to show before your src or fallbackImage load. Can optionally be passed in as a react element.


timeout in millisecond before to show initialImage. Default is null which should initialImage immediately


A callback called if initial image loads successfully, will be called with successful image url.


A callback called if initial image load fails, will be called with failing image url.

spread props

This component also utilizes jsx spread attributes to pass along custom image attributes such as alt tags and className. Only valid dom props will be spread to the image tag.


import React From "react";
import ReactImageFallback from "react-image-fallback";
export default class ShowImage extends React.Component {
    render() {
        return (
                    alt="cool image should be here"
                    className="my-image" />

Copyright (C) 2017 Social Tables, Inc. ( All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package Sidebar


npm i react-image-fallback

Weekly Downloads






Unpacked Size

13.8 kB

Total Files


Last publish


  • conorhastings
  • tiansijie
  • socialtables-engineering