Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional svgXmlData doesn't work properly #20

Open
danibonilha opened this issue Apr 21, 2020 · 1 comment
Open

Conditional svgXmlData doesn't work properly #20

danibonilha opened this issue Apr 21, 2020 · 1 comment

Comments

@danibonilha
Copy link

On version 0.2.0

When using conditional data, svgXmlData only updates on second render, example:

import SvgRenderer from 'react-native-svg-renderer';

const TestSvgRenderer = ({ condition = true }) => (
  <View style={styles.container}>
    <SvgRenderer
      width="200"
      height="200"
      svgXmlData={condition ?  'svgTrue' : ' svgFalse'}
    />
  </View>
);

If condition changes to false at the first time it will still render svgTrue

@acb
Copy link

acb commented Jan 2, 2021

I had a similar issue to this and the root cause was that I was rendering these inside a loop and the key that I was putting on the parent element wasn't unique. Essentially I had several components that each had

let icons = this.props.list.map((item, i) => {
  return <View key={i}><SvgRenderer svgXmlData={item.icon} /></View>
});

and if I swapped the component's position then they would render each other's SVG instead of the one they were supposed to have.

Updating the key to be key={item.id + i} fixed the issue. If you're in a similar situation you may want to double check that your keys are globally unique otherwise the SvgRenderer can collide with the wrong state, causing its updates to lag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants