Created
July 10, 2018 21:31
-
-
Save marensas/d69c723222ea9cd3ebb88ac58c6ac178 to your computer and use it in GitHub Desktop.
App.jsx with Button component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Question from './components/Question'; | |
import Button from './components/Button'; | |
class App extends React.Component { | |
constructor (props) { | |
super(props); | |
this.state = { | |
data: [], | |
currentTicket: 0, | |
finished: false, | |
score: '', | |
}; | |
} | |
componentDidMount() { | |
this.getData(); | |
} | |
getData = () => { | |
fetch('/tickets.json').then((response) => { | |
return response.json(); | |
}).then((data) => { | |
this.setState({ data }); | |
}); | |
} | |
nextTicket = () => { | |
const { currentTicket, data } = this.state; | |
if (currentTicket === data.length -1) { | |
return this.setState({ currentTicket: 0 }); | |
} | |
return this.setState({ currentTicket: currentTicket +1 }); | |
} | |
render () { | |
const { data, currentTicket } = this.state; | |
const question = data && data.length > 0 ? data[currentTicket].question : ''; | |
return ( | |
<div> | |
<h1>Testas</h1> | |
<div> | |
<div> | |
<Question question={question} /> | |
</div> | |
<div> | |
<Button name="Next ticket" handler={() => this.nextTicket} /> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment