Skip to content

Commit 2abc50c

Browse files
committed
setinterval for binary- still need to set sttate
relates to #8
1 parent d5c5a40 commit 2abc50c

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

client/src/components/Binary/Choices_appear.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component } from "react";
22
import { browserHistory } from "react-router";
33
import axios from "axios";
4+
import EachChoice from "./Each_choice";
45

56
class ChoicesAppear extends Component {
67
constructor(props) {
@@ -24,12 +25,7 @@ class ChoicesAppear extends Component {
2425
render() {
2526
return (
2627
<div>
27-
{this.state.choices.map((data, index) => (
28-
<div key={index}>
29-
<p>{data.Choices_left}</p>
30-
<p>{data.Choices_right}</p>
31-
</div>
32-
))}
28+
<EachChoice trial_choices={this.state.choices} />
3329
</div>
3430
);
3531
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from "react";
2+
import { Link } from "react-router-dom";
3+
import { Route, withRouter } from "react-router-dom";
4+
5+
class EachChoice extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
id: 0
10+
};
11+
}
12+
13+
componentDidMount() {
14+
let count = 0;
15+
console.log("countttt: ", count);
16+
if (count === this.props.trial_choices.length) {
17+
clearInterval(this.timer);
18+
console.log("wronggg");
19+
}
20+
this.timer = setInterval(() => {
21+
count += 1;
22+
this.setState({ id: count });
23+
console.log("interval count: ", count);
24+
}, 2000);
25+
}
26+
27+
render() {
28+
console.log(this.props.trial_choices.length);
29+
if (this.props.trial_choices.length === 0) return <h3>Loading...</h3>;
30+
return (
31+
<div>
32+
<p>{this.props.trial_choices[this.state.id].Choices_left}</p>
33+
<p>{this.props.trial_choices[this.state.id].Choices_right}</p>
34+
hello
35+
</div>
36+
);
37+
}
38+
}
39+
40+
export default withRouter(EachChoice);

0 commit comments

Comments
 (0)