Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jopp289/domains/progmans.net/public_html/engine/modules/show.full.php on line 243 react class api fetch json » Шпаргалки
Заголовок
react class api fetch json
WEB

import React, { Component } from 'react'
import RecipeList from './components/RecipeList
export default class test extends Component {
  constructor(props) {
    super(props)
    this.state = {
      apiResponse: [],
    }
  }
  componentDidMount() {
    fetch(`https://api.myjson.com/bins/t7szj`)
      .then(data => data.json)
      .then(apiResponse => this.setState({ apiResponse }))
  }
  render() {
    return (
      <div>
          <RecipeList recipes={this.state.recipes}>
      </div>
    )
  }
}

 

https://medium.com/better-programming/lets-learn-react-hooks-and-context-api-by-building-a-recipe-search-app-63be9d9e1801


Теги: