{"id":21822719,"url":"https://github.com/unirakun/react-img-fallback","last_synced_at":"2025-04-14T03:52:39.191Z","repository":{"id":40945197,"uuid":"86832749","full_name":"unirakun/react-img-fallback","owner":"unirakun","description":"React Component print a fallback if img src doesn't here or error occured","archived":false,"fork":false,"pushed_at":"2022-12-06T20:52:57.000Z","size":644,"stargazers_count":4,"open_issues_count":21,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T17:51:54.646Z","etag":null,"topics":["fallback","image","img","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unirakun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-31T15:16:16.000Z","updated_at":"2020-07-01T14:03:43.000Z","dependencies_parsed_at":"2023-01-23T12:45:29.808Z","dependency_job_id":null,"html_url":"https://github.com/unirakun/react-img-fallback","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unirakun%2Freact-img-fallback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unirakun%2Freact-img-fallback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unirakun%2Freact-img-fallback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unirakun%2Freact-img-fallback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unirakun","download_url":"https://codeload.github.com/unirakun/react-img-fallback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819359,"owners_count":21166474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fallback","image","img","react"],"created_at":"2024-11-27T17:17:07.137Z","updated_at":"2025-04-14T03:52:39.147Z","avatar_url":"https://github.com/unirakun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-img-fallback\n[![CircleCI](https://circleci.com/gh/unirakun/react-img-fallback.svg?\u0026style=shield\u0026circle-token=)](https://circleci.com/gh/unirakun/react-img-fallback/tree/master) [![NPM Version](https://badge.fury.io/js/react-img-fallback.svg)](https://www.npmjs.com/package/react-img-fallback) [![Coverage Status](https://coveralls.io/repos/github/Trampss/react-img-fallback/badge.svg?branch=master)](https://coveralls.io/github/Trampss/react-img-fallback?branch=master)\n\n## Install\n`yarn add react-img-fallback`\n\nor\n\n`npm install --save react-img-fallback`\n\n## Description\nThis component is designed for implement the `onError` function of Image component, just one time.\nThe goal is to give a new source url or a fallback component when the `src` url is on error.\n\n## Prerequisites\nThis library use `recompose` for optimize rendering : https://github.com/acdlite/recompose\n\n## API\n| PropTypes     |       Type (Default)     |    Description  |\n|:--------------|:------------------------:|----------------:|\n| **style**     | `object` (empty)         | inline style extends component     |\n| **className** | `string` (empty)         | name class extends component       |\n| **src**       | `string` (undefined)     | url source extends image component |\n| **alt**       | `string` (empty)         | alt tag extends image component    |\n| **fallback**  |  `Component` or `string` | the fallback if image on error     |\n| **onClick**   | `function` (undefined)   | callback called when image clicked |\n\n## Component by an example\n### URL images to print : ![alt tag](https://s-media-cache-ak0.pinimg.com/736x/fe/92/c0/fe92c04bd02a5f740a7611c6379b2878.jpg)\nWe want to draw this image (**BeautifulPonyWithHorn.jsx**):\n```es6\nimport React from 'react'\nimport ImgFallback from 'react-img-fallback'\n\nexport default () =\u003e {\n\n  /* Url for take a beautyful unicorn ! */\n  const ponyUrl = 'https://s-media-cache-ak0.pinimg.com/736x/fe/92/c0/fe92c04bd02a5f740a7611c6379b2878.jpg'\n\n  /* Fallback Url (sick pony with horn) */\n  const fallbackUrl = 'http://sickponywithouthorn.png'\n\n  return (\n    \u003cImgFallback\n      style={{width: '250px'}}\n      src={ponyUrl}\n      alt=\"ponyWithHorn\"\n      fallback={FallbackUrl}\n      onClick={() =\u003e alert('unicorn POWER')}\n    \u003e\n    \u003c/ImgFallback\u003e\n  )\n}\n```\n\nIf pony is sick, the fallback url is printed on img fallback !\n\n### If your fallback is a component\n[Demo](https://www.webpackbin.com/bins/-KgjzE83zUAP2XLyVM6o) is ready and online with WebPackBin\n```es6\nimport React from 'react'\nimport ImgFallback from 'react-img-fallback'\n\nexport default () =\u003e {\n  /* Url for take a beautyful unicorn ! */\n  const ponyUrl = 'https://s-media-cache-ak0.pinimg.com/736x/fe/92/c0/fe92c04bd02a5f740a7611c6379b2878.jpg'\n\n  /* Fallback Component (sick pony with horn) */\n  const Fallback = (\n    \u003cpre\u003e\n                         n\n              |\\   |  or\n             _| \\-/ic\n            /    un\n          //    ~ + \\\n         //         |\n        //    \\      \\\n       |||     | .  .|\n      ///     / \\___/\n    \u003c/pre\u003e\n   )\n\n    \u003cImgFallback\n      style={{width: '250px'}}\n      src={ponyUrl}\n      alt=\"ponyWithHorn\"\n      fallback={Fallback}\n      onClick={() =\u003e alert('unicorn POWER')}\n    \u003e\n    \u003c/ImgFallback\u003e\n  )\n}\n```\n\n# About uni rakun\n**uni rakun** is created by two passionate french developers.\n\nDo you want to contact them ? Go to their [website](https://unirakun.fr)\n\n\u003ctable border=\"0\"\u003e\n \u003ctr\u003e\n  \u003ctd align=\"center\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/26094222?s=460\u0026v=4\" width=\"100\" /\u003e\u003c/td\u003e\n  \u003ctd align=\"center\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/17828231?s=460\u0026v=4\" width=\"100\" /\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/guillaumecrespel\"\u003eGuillaume CRESPEL\u003c/a\u003e\u003c/td\u003e\n  \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/fabienjuif\"\u003eFabien JUIF\u003c/a\u003e\u003c/td\u003e\n\u003c/table\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funirakun%2Freact-img-fallback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funirakun%2Freact-img-fallback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funirakun%2Freact-img-fallback/lists"}