Back

Getting error in FSD 101

Created 1 year ago
60 Views
2 Comments
Naveenkumar1
@Naveenkumar1
Naveenkumar1
@Naveenkumar1Profile is locked. Login

After login in to the home page, the data is not getting corrrectly, it's like {}.

Code in Home.jsx

import React, { useEffect } from 'react';

import { Container,Button } from 'react-bootstrap'

import "../Styles/Home.css";

import axios from "axios";

import API_URL from '../../config/global';

const Home = () => {

useEffect(() =>{

const user = JSON.parse(localStorage.getItem("userInfo"));

if(user && user.token){

getData(user.token);

}

},[]);

const getData = async (token) =>{

try{

const config = {

headers:{

Authorization:token,

},

};

const response =await axios.get(`${API_URL}/home`,config);

console.log(response);

}catch (e){

console.log(e);

}

};

return (

<Container>

<h1>Welcome to our Website</h1>

<p>We are here to serve you</p>

<Button variant="primary" type="submit">

Get Started

</Button>

</Container>

);

};

export default Home;

Browser Console

  1. {data: {…}, status: 200, statusText: 'OK', headers: AxiosHeaders, config: {…}, …}

    1. config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}

    2. data: {}

    3. headers: AxiosHeaders {content-length: '2', content-type: 'application/json; charset=utf-8'}

    4. request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}

    5. status: 200

    6. statusText: "OK"

    7. [[Prototype]]: Object

Comments (2)
Please login to comment.