Skip to content

Commit 02ccfc3

Browse files
committed
Update render method to apply keys to children and indicator
1 parent 9bbf00a commit 02ccfc3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import cleanProps from 'clean-react-props';
4+
import uuid from 'uuid/v4';
45

56
class Rotator extends Component {
67
constructor(props) {
78
super(props);
89

910
this.state = {
1011
index: props.index,
12+
keyPrefix: `rotator-${uuid()}`,
1113
};
1214

1315
this.onIndicatorChange = this.onIndicatorChange.bind(this);
@@ -88,11 +90,13 @@ class Rotator extends Component {
8890

8991
const {
9092
index,
93+
keyPrefix,
9194
} = this.state;
9295

9396
const clonedChildren = React.Children.toArray(children).map((child, childIndex) => {
9497
return React.cloneElement(child, {
9598
index: childIndex,
99+
key: `${keyPrefix}-child-${childIndex}`,
96100
position: (index - childIndex) * -1,
97101
onActive: this.onItemActive,
98102
onFinish: this.onItemFinish,
@@ -102,6 +106,7 @@ class Rotator extends Component {
102106
const clonedIndicator = indicator
103107
? React.cloneElement(indicator, {
104108
index,
109+
key: `${keyPrefix}-indicator`,
105110
length: children.length,
106111
onChange: this.onIndicatorChange,
107112
})

0 commit comments

Comments
 (0)