Prevents SvgUri crashes when uri is invalid and adds fallback prop (#2071)

SvgUri component crashes an app when uri with SVG returns html or some other content instead of valid SVG.
This change prevents those crashes and adds fallback property of JSX type which is rendered instead of corrupted SVG.
This commit is contained in:
PiotrWszolek
2023-07-06 14:21:20 +02:00
committed by GitHub
parent 7983ad2ca6
commit e04a159b46
4 changed files with 67 additions and 10 deletions

View File

@@ -122,11 +122,13 @@ export default function TestComponent() {
Both `SvgUri` and `SvgCssUri` log errors to the console, but otherwise ignore them.
You can set property `onError` if you want to handle errors such as resource not
existing in a different way.
existing in a different way and `fallback` if you want to render another component
instead in such case.
```jsx
import * as React from 'react';
import { SvgUri } from 'react-native-svg';
import { SvgFallback } from './components/SvgFallback';
export default () => {
const [uri, setUri] = React.useState(
@@ -140,6 +142,7 @@ export default () => {
width="100%"
height="100%"
uri={uri}
fallback={<SvgFallback />}
/>
);
};