Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Show warning when key is not provided #1

Closed
igolkotek opened this issue Nov 17, 2015 · 2 comments
Closed

Show warning when key is not provided #1

igolkotek opened this issue Nov 17, 2015 · 2 comments

Comments

@igolkotek
Copy link

Hi,
Just tried to repeat your example with a pair of MdFavoriteBorder/MdFavorite and toggling active state by Click.
Console log confirms this.state.active is changed by click, but icon change not happen. (((

import { MorphReplace } from 'react-svg-morph';
import MdFavoriteBorder from 'react-icons/lib/md/favorite-border';
import MdFavorite from 'react-icons/lib/md/favorite';

toggleChecked: function() {
    this.setState({active: !this.state.active});
  },
  render() {
    var icon;
    if(this.state.active) {
      console.log("active");
      icon = <MdFavoriteBorder />;
    } else {
      console.log("passive");
      icon = <MdFavorite />;
    }
    return (
      <div onClick={this.toggleChecked} >
        <MorphReplace >
          { icon }
        </MorphReplace>
      </div>
    );
  }

Can't understand the reason.
Could you please help

Iho

@gorangajic gorangajic changed the title Transition fails Show warning when key is not provided Nov 17, 2015
@gorangajic
Copy link
Owner

you will need to provide key prop to both icons

    if (this.state.active) {
      console.log("active");
      icon = <MdFavoriteBorder key="favorite-border" />;
    } else {
      console.log("passive");
      icon = <MdFavorite key="favorite" />;
    }

@igolkotek
Copy link
Author

OK, thanks

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

No branches or pull requests

2 participants