API Requests

Learn React in 2020

What is an API

  • API stands for: Application Program Interface.
  • It's the way for programs to communicate with other programs
  • Used to fetch data, communicate with db or any other services
  • APIs are so powerful you can deconstruct your server into APIs

How does API work

  • A request is sent from one machine to a server.
  • The server can do many operation before responding back.

Client Side

Server Side

Request details in URL

Response in JSON or XML

Basic Hooks

const [city, setCity] =  useState('')
useState(Initial Value) = Array[Variable, Updating Function]
  • Hooks are way to manage state. What is state? 
  • State is a variable that defines the 'STATE' of the app at any specific point in time. 
  • useState hook takes initial value as argument.
  • It returns two things, one the variable itself. Two the setting function.
  • Calling the setting function forces a re-redner in the app. 

State change (Mutation)

State change (Mutation)

LifeCycle Methods

const [city, setCity] =  useState('')
useState(Initial Value) = Array[Variable, Updating Function]
  • useEffect will run once the component is mounted.
  • It will re-run once any of its dependencies are changed.
  • It can hold a return function to be run when the component is unmounted

Subscribe for more!

Shehata@msmo.io

github.com/ms-mousa

Learn React in 2020 - 07 APIs

By msmo

Learn React in 2020 - 07 APIs

  • 239