Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 9f151be

Browse files
committed
fixes duplicate ids when multiple Dat components are used in one document
1 parent ade0808 commit 9f151be

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Dat.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import cloneDeep from 'lodash.clonedeep';
44
import isUndefined from 'lodash.isundefined';
55
import React, { PropTypes, cloneElement } from 'react';
66

7+
function uuid(a) {
8+
// https://gist.github.com/jed/982883
9+
return a ? (a^Math.random()*16>>a/4).toString(16) : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, uuid);
10+
}
11+
712
class Dat extends React.Component {
813

914
static propTypes = {
@@ -36,7 +41,7 @@ class Dat extends React.Component {
3641
return React.Children.toArray(children).map((child, i) => {
3742
const liveUpdate = isUndefined(child.props.liveUpdate) ? this.props.liveUpdate : child.props.liveUpdate;
3843
return cloneElement(child, {
39-
id: `__react_dat_gui_${i}__`,
44+
id: uuid(),
4045
key: i,
4146
data,
4247
liveUpdate,

0 commit comments

Comments
 (0)