Skip to content

Commit d063987

Browse files
committed
Use React.cloneElement to give array elements keys instead of hardcoding
1 parent c0f80eb commit d063987

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/plugins/topbar/topbar.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { cloneElement } from "react"
22
import PropTypes from "prop-types"
33

44
//import "./topbar.less"
@@ -112,7 +112,7 @@ export default class Topbar extends React.Component {
112112
})
113113

114114
control.push(
115-
<label key={1} className="select-label" htmlFor="select"><span>Select a spec</span>
115+
<label className="select-label" htmlFor="select"><span>Select a spec</span>
116116
<select id="select" disabled={isLoading} onChange={ this.onUrlSelect } value={urls[this.state.selectedIndex].url}>
117117
{rows}
118118
</select>
@@ -121,8 +121,8 @@ export default class Topbar extends React.Component {
121121
}
122122
else {
123123
formOnSubmit = this.downloadUrl
124-
control.push(<input key={1} className="download-url-input" type="text" onChange={ this.onUrlChange } value={this.state.url} disabled={isLoading} style={inputStyle} />)
125-
control.push(<Button key={2} className="download-url-button" onClick={ this.downloadUrl }>Explore</Button>)
124+
control.push(<input className="download-url-input" type="text" onChange={ this.onUrlChange } value={this.state.url} disabled={isLoading} style={inputStyle} />)
125+
control.push(<Button className="download-url-button" onClick={ this.downloadUrl }>Explore</Button>)
126126
}
127127

128128
return (
@@ -134,7 +134,7 @@ export default class Topbar extends React.Component {
134134
<span>swagger</span>
135135
</Link>
136136
<form className="download-url-wrapper" onSubmit={formOnSubmit}>
137-
{control}
137+
{control.map((el, i) => cloneElement(el, { key: i }))}
138138
</form>
139139
</div>
140140
</div>

0 commit comments

Comments
 (0)