GithubHelp home page GithubHelp logo

yildirimesutx / react-crypto-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 305 KB

Home Page: https://react-crypto-app-lilac.vercel.app/

HTML 16.73% CSS 34.35% JavaScript 48.93%
axios fecth-api javascript react

react-crypto-app's Introduction

React içinden fetch() ve axios ile veri almak

API'den veri almak asekron bir işlemdir, sayfa render edilirken veride aynı zamanda gelebilir.

useEffect hook u içinde axios ve fecth kullanıyoruz

calback func ve dibendis alıyor içerisine

***fetch kullanımı =>

fetch react yapısı içinde olan özellik,kuruluma ihtiyacı yok

fetch('https://api.coingecko.com/api/v3/coins/markets?vs_currency=INR&order=market_cap_desc&per_page=100&page=1&sparkline=false') .then(response => response.json()) .then( response=> console.log(response))

---burada fetch içerisinden promis olarak dönen veriyi json şekl,nde alabilmek için fetch in bir özelliği olan json ile then içerisinde çağırdık, ikinci seferde json veriyi göstermek için kullandık,,

bu verileri sayfada göstermek için yakalamamız ve hafızaya almamız gerekiyor,

bu işlem için useState() hook unu kullanıyoruz.

const [coin, setCoin] = useState()

buradaki; coin => state tutacak değer, setCoin=> state değiştirecek fonksiyon

bu bilgileri ekrana yazdırmak için gelen verinin içerisine map ile giriyoruz ve

{ coin.map(coins=>{ return (

<img src={coins.image} alt="" style={{width :'20px'}} /> {coins.name}
)}) }

*** axios kullanımı =>

axios kullanabilmek için import ve install edilmesi gerekiyor

npm install axios

useEffect(() =>{

axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=INR&order=market_cap_desc&per_page=100&page=1&sparkline=false') .then(response => setCoin(response.data)) .catch(error => console.log({error})); }, []) burada gelen response data ile yakaladık

{ coin.map(coins=>{ return (

<img src={coins.image} alt="" style={{width :'20px'}} /> {coins.name}
)}) }

*** bir değişkene atayarak yapma

const getCoin = ()=> axios.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=INR&order=market_cap_desc&per_page=100&page=1&sparkline=false') .then(res=>{ setCoin(res.data) // console.log(res.data[0].name) })

burada değişkene atandığnda then kullanılmasaydı, async await kullanılması gerekirdi.

ayrıca useEffect içinde promis yapısı kullanılmıyor yanı, useEffect içinde async await yapısı kullanmıyoruz.

useEffect(() => { getCoin() }, [])

kaynakça:

  1. https://medium.com/kocsistem/a-dan-z-ye-react-facce30533d0

  2. https://www.youtube.com/watch?v=jNwU5gcrIrg&ab_channel=ReactDersleri

react-crypto-app's People

Contributors

yildirimesutx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.