Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- page[0].infoBloco[0].tabela[0].dados[0].fonte.nome
- TypeError: this.state.page[0] is undefined[Learn More] index.jsx:49
- [
- {
- "infoBloco": [
- {
- "tabela": [
- {
- "dados": [
- {
- "fonte": {
- "url": "http://www.google.com",
- "nome": "Site de buscas"
- }
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "infoBloco": [
- {
- "tabela": [
- {
- "dados": [
- {
- "fonte": {
- "url": "http://www.yahoo.com",
- "nome": "Outro site de buscas"
- }
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- import React, { Component } from "react"
- export default class extends Component {
- constructor(props) {
- super(props)
- this.state = {
- page: [],
- }
- }
- componentDidMount() {
- this.getData()
- }
- getData = async () => {
- await fetch('http://localhost:3003/api')
- .then(resp => resp.json())
- .then(data => this.setState({
- ...this.state,
- page: data,
- }))
- }
- render() {
- console.log(this.state.page[0].infoBloco[0].tabela[0].dados[0].fonte.nome)
- return (
- <div>
- Exemplo
- </div>
- )
- }
- }
Add Comment
Please, Sign In to add comment