Skip to content

Instantly share code, notes, and snippets.

@marensas
Created July 10, 2018 21:10
Show Gist options
  • Save marensas/bf58eacfc06403bc47fb5dc18ad8503d to your computer and use it in GitHub Desktop.
Save marensas/bf58eacfc06403bc47fb5dc18ad8503d to your computer and use it in GitHub Desktop.
App.jsx with Question component
import React from "react";
import Question from './components/Question';
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 });
});
}
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>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment