Skip to content

Commit d896241

Browse files
committed
[chore] fix multiple modal example.
1 parent ce2b34e commit d896241

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Diff for: examples/basic/multiple_modals/index.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React, { Component } from 'react';
22
import Modal from 'react-modal';
33

4-
function List(props) {
5-
return props.items.map((x, i) => (
6-
<div key={i} onClick={props.onItemClick(i)}>
7-
<a href="javascript:void(0)">{x}</a>
8-
</div>
9-
));
4+
class List extends React.Component {
5+
render() {
6+
return (
7+
<div>
8+
{this.props.items.map((x, i) => (
9+
<div key={i} onClick={this.props.onItemClick(i)}>
10+
<a href="javascript:void(0)">{x}</a>
11+
</div>))}
12+
</div>
13+
);
14+
}
1015
}
1116

1217
class MultipleModals extends Component {
@@ -27,7 +32,6 @@ class MultipleModals extends Component {
2732
return;
2833
}
2934
this.setState({
30-
...this.state,
3135
items: [],
3236
listItemsIsOpen: true,
3337
loading: true
@@ -38,7 +42,6 @@ class MultipleModals extends Component {
3842
// opportunity to validate something and keep the modal open even if it
3943
// requested to be closed
4044
this.setState({
41-
...this.state,
4245
listItemsIsOpen: false,
4346
loading: false
4447
});
@@ -47,22 +50,21 @@ class MultipleModals extends Component {
4750
handleOnAfterOpenModal = () => {
4851
// when ready, we can access the available refs.
4952
(new Promise((resolve, reject) => {
50-
setTimeout(() => resolve(true), 1000);
53+
setTimeout(() => resolve(true), 500);
5154
})).then(res => {
5255
this.setState({
53-
...this.state,
5456
items: [1, 2, 3, 4, 5].map(x => `Item ${x}`),
5557
loading: false
5658
});
5759
});
5860
}
5961

6062
onItemClick = index => event => {
61-
this.setState({ ...this.state, currentItem: index });
63+
this.setState({ currentItem: index });
6264
}
6365

6466
cleanCurrentItem = () => {
65-
this.setState({ ...this.state, currentItem: -1 });
67+
this.setState({ currentItem: -1 });
6668
}
6769

6870
render() {

0 commit comments

Comments
 (0)