Skip to content

Commit 034f5cc

Browse files
committed
converted actioncontainer to functional component and added props validation
1 parent a9fb2f8 commit 034f5cc

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed
Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import Action from '../components/Action';
34

4-
class ActionContainer extends Component {
5-
constructor(props) {
6-
super(props);
5+
const ActionContainer = ({
6+
snapshots,
7+
snapshotIndex,
8+
handleChangeSnapshot,
9+
handleJumpSnapshot,
10+
emptySnapshot,
11+
}) => {
12+
let actionsArr = [];
13+
if (snapshots.length > 0) {
14+
actionsArr = snapshots.map((snapshot, index) => {
15+
const selected = index === snapshotIndex;
16+
return (
17+
<Action
18+
key={`action${index}`}
19+
index={index}
20+
snapshot={snapshot}
21+
selected={selected}
22+
handleChangeSnapshot={handleChangeSnapshot}
23+
handleJumpSnapshot={handleJumpSnapshot}
24+
/>
25+
);
26+
});
727
}
8-
9-
render() {
10-
const {
11-
snapshots,
12-
snapshotIndex,
13-
handleChangeSnapshot,
14-
handleJumpSnapshot,
15-
emptySnapshot,
16-
} = this.props;
17-
let actionsArr = [];
18-
if (snapshots.length > 0) {
19-
actionsArr = snapshots.map((snapshot, index) => {
20-
const selected = index === snapshotIndex;
21-
return (
22-
<Action
23-
key={`action${index}`}
24-
index={index}
25-
snapshot={snapshot}
26-
selected={selected}
27-
handleChangeSnapshot={handleChangeSnapshot}
28-
handleJumpSnapshot={handleJumpSnapshot}
29-
/>
30-
);
31-
});
32-
}
33-
return (
34-
<div className="action-container">
35-
<div className="action-component">
36-
<div className="empty-button" onClick={emptySnapshot}>
37-
emptySnapshot
38-
</div>
28+
return (
29+
<div className="action-container">
30+
<div className="action-component">
31+
<div className="empty-button" onClick={emptySnapshot}>
32+
emptySnapshot
3933
</div>
40-
<div>{actionsArr}</div>
4134
</div>
42-
);
43-
}
44-
}
35+
<div>{actionsArr}</div>
36+
</div>
37+
);
38+
};
39+
40+
ActionContainer.propTypes = {
41+
snapshots: PropTypes.arrayOf(
42+
PropTypes.object,
43+
).isRequired,
44+
snapshotIndex: PropTypes.number.isRequired,
45+
handleChangeSnapshot: PropTypes.func.isRequired,
46+
handleJumpSnapshot: PropTypes.func.isRequired,
47+
emptySnapshot: PropTypes.func.isRequired,
48+
};
4549

4650
export default ActionContainer;

0 commit comments

Comments
 (0)