Skip to content

Commit dba487e

Browse files
committed
Change last class React.Component by functional implementation
1 parent 03f8b3a commit dba487e

File tree

2 files changed

+169
-192
lines changed

2 files changed

+169
-192
lines changed

src/web/wizard/components/inputs/Description.jsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,37 @@
1515
* <http://www.mongodb.com/licensing/server-side-public-license>.
1616
*/
1717

18-
import PropTypes from 'prop-types';
19-
import React from 'react';
18+
import React, {useState} from 'react';
2019
import { Input, Row, Col } from 'components/bootstrap';
2120
import { FormattedMessage } from 'react-intl';
2221

23-
class Description extends React.Component {
22+
const Description = ({description, onUpdate}) => {
2423

25-
static propTypes = {
26-
onUpdate: PropTypes.func,
27-
};
24+
const [state, setState] = useState({description: description});
2825

29-
static defaultProps = {
30-
description:'',
26+
const _onValueChanged = (field) => {
27+
return e => {
28+
setState({description: e.target.value});
29+
onUpdate(field, e.target.value);
30+
};
3131
};
3232

33-
state = {
34-
description: this.props.description
35-
};
33+
return (
34+
<Row>
35+
<Col md={2} style={{ marginTop: 5, marginBottom: 0 }}>
36+
<label className="pull-right" ><FormattedMessage id= "wizard.titleDescription" defaultMessage= "Description (optional)" /></label>
37+
</Col>
38+
<Col md={10}>
39+
<Input style={{minWidth: 600}} id="description" name="description" type="textarea"
40+
onChange={_onValueChanged("description")} defaultValue={state.description}/>
41+
</Col>
42+
</Row>
43+
);
44+
}
3645

37-
_onValueChanged(field) {
38-
return e => {
39-
this.props.onUpdate(field, e.target.value);
40-
};
41-
}
42-
43-
render() {
44-
return (
45-
<Row>
46-
<Col md={2} style={{ marginTop: 5, marginBottom: 0 }}>
47-
<label className="pull-right" ><FormattedMessage id= "wizard.titleDescription" defaultMessage= "Description (optional)" /></label>
48-
</Col>
49-
<Col md={10}>
50-
<Input style={{minWidth: 600}} ref="description" id="description" name="description" type="textarea"
51-
onChange={this._onValueChanged("description")} defaultValue={this.state.description}/>
52-
</Col>
53-
</Row>
54-
);
55-
}
46+
Description.defaultProps = {
47+
description: '',
48+
onUpdate: () => {}
5649
}
5750

5851
export default Description;

0 commit comments

Comments
 (0)