Guest User

Untitled

a guest
Jun 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. page[0].infoBloco[0].tabela[0].dados[0].fonte.nome
  2.  
  3. TypeError: this.state.page[0] is undefined[Learn More] index.jsx:49
  4.  
  5. [
  6. {
  7. "infoBloco": [
  8. {
  9. "tabela": [
  10. {
  11. "dados": [
  12. {
  13. "fonte": {
  14. "url": "http://www.google.com",
  15. "nome": "Site de buscas"
  16. }
  17. }
  18. ]
  19. }
  20. ]
  21. }
  22. ]
  23. },
  24. {
  25. "infoBloco": [
  26. {
  27. "tabela": [
  28. {
  29. "dados": [
  30. {
  31. "fonte": {
  32. "url": "http://www.yahoo.com",
  33. "nome": "Outro site de buscas"
  34. }
  35. }
  36. ]
  37. }
  38. ]
  39. }
  40. ]
  41. }
  42. ]
  43.  
  44. import React, { Component } from "react"
  45.  
  46. export default class extends Component {
  47.  
  48. constructor(props) {
  49. super(props)
  50. this.state = {
  51. page: [],
  52. }
  53. }
  54.  
  55. componentDidMount() {
  56. this.getData()
  57. }
  58.  
  59. getData = async () => {
  60. await fetch('http://localhost:3003/api')
  61. .then(resp => resp.json())
  62. .then(data => this.setState({
  63. ...this.state,
  64. page: data,
  65. }))
  66. }
  67.  
  68. render() {
  69.  
  70. console.log(this.state.page[0].infoBloco[0].tabela[0].dados[0].fonte.nome)
  71.  
  72. return (
  73. <div>
  74. Exemplo
  75. </div>
  76. )
  77. }
  78. }
Add Comment
Please, Sign In to add comment