Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Is it right way in React to fetch data from APIs by setting to state/props and fetching from there ?

 
Ranch Foreman
Posts: 1805
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In React one can fetch data from REST APIs by using Fetch keyword. After fetching the data ,one way to render it on the UI is to set it into state/props and fetching it from there while displaying.Is this way correct or there is a different way ?
Thanks
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fetch isn't a keyword, it's a function. (And it's not uppercased.)

Changing props or state is the accepted way to dynamically change the UI. Which you use depends upon where in the component hierarchy the fetch occurs.
 
Monica Shiralkar
Ranch Foreman
Posts: 1805
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic