Click here to Skip to main content
15,742,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I want to create a unique function that will return value back as data using axios and have local data as json file.But i need to call it on Sidebar.js to have access to the json file so can consume it.

What I have tried:

<pre>import React,{Component, useEffect, useState} from 'react';
import axios from 'axios'

class Sidebar extends Component {

  // constructor.

  constructor(props) {
    this.state = { status: true };

  render() {
    return (
      <div className="side">
    export default Sidebar

// function for using axios
function Sidebar() {
  const [product, setProduct] = useState([]);

  useEffect(() => {
      .then((res) => setUsers(
      .catch((err) => console.log(err));
  }, []);

  return (
        {, index) => (
          <li key={index}>
            {} {product.title}

export default Sidebar;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900