this is my first question on here so I hope I am doing this right. I am working on a trivia game using React and the API Open Trivia Database. I made two separate pages for the components Questions and Categories but I can't figure out how to get them onto the main page... and frankly where to go from there. Thank you for your time.
Here is my main page:
import React from 'react'
import './App.css'
// import axios from 'axios'
import Questions from './components/questions'
import Categories from './components/categories'
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
questions: [],
categories: []
// score: 0,
}
}
render () {
return (
<div className='App'>
<h2>Trivia Game</h2>
{this.state.Questions}
</div>
)
}
}
export default App
and here is the Question page:
import React from 'react'
import axios from 'axios'
class Questions extends React.Component {
constructor () {
super()
this.state = {
questions: []
}
}
componentDidMount () {
axios
.get('https://opentdb.com/api.php?amount=10')
.then(response => {
console.log(response.data)
this.setState({
questions: response.data.results
})
})
}
componentWillUnmount () {
console.log('componentDidUnmount')
}
render () {
return (
<div className='Questions'>
<h2>Questions</h2>
<ul>
{this.state.questions.map((question, index) => (
<li key={index}>{question.question}</li>
))}
</ul>
</div>
)
}
}
export default Questions