88. Add Auth token to the API URLs for making HTTP axios requests in the React Redux App - ReactJS.

preview_player
Показать описание
Hi Friends

In this video, we will see how to add the auth token to the API URLs as the query params for making the HTTP Axios requests in the React Redux App - ReactJS.

The code is deployed in my Github account.

If you like my video, please subscribe to my channel.

#React #leelawebdev

Join this channel to get access to perks:
Рекомендации по теме
Комментарии
Автор

Is there any better way to achieve this??
Passing and parsing token seems a lot of trouble

kriteshkaushik
Автор

why .get method is not working for me when ${BASE_URL} is used? any advise please.

import React, { useState, useEffect } from 'react'
import './Stats.css'
import axios from "axios";
import StatsRow from './StatsRow'

const TOKEN =

let tempStocksData = [];

function Stats() {

const [stockData, setstockData] =useState([])

const getStocksData = (stock) => {
return axios


.catch((error) => {
console.error("Error", error.message);
});
};

useEffect(()=>{

const stocksList = ["AAPL", "MSFT", "TSLA", "FB", "BABA", "UBER", "DIS", "SBUX"];

let promises = [];
stocksList.map((stock) => (
promises.push(
getStocksData(stock)
.then ((res) => {
tempStocksData.push({
name: stock,
...res.data
});
})
)
));

{


})
}, [])

return (
<div className="stats">
<div
<div className="stats__header">
<p>Stocks</p>
</div>
<div className="stats__content">
<div className="stats__rows">
</div>
</div>

<div className="stats__header">
<p>Lits</p>
</div>

<div className="stats__content">
<div className="stats__rows">
{/* stocks we can buy*/}
{stockData.map((stock) => (
<StatsRow />
))}
</div>
</div>
</div>
</div>
)
}
export default Stats

kumarisapna