'React Native how to export API response

how to export API response to another components? i have axios that bring data from the back-end to the front-end, can i export the response data to another component/screen or i have to do Fetch/axios on each part i want render data on it

i have the API response on Home page, so i can export the data

Home.js

.....
const Home = ({ navigation }) => {
  const [ChartData, setChartData] = useState([]);
  const [BalanceData, setBalanceData] = useState([]);
  const [ExpensesData, setExpensesData] = useState([]);
  const [SavingsData, setSavingsData] = useState([]);
  const [IncomeData, setIncomeData] = useState([]);
  const [LoansData, setLoansData] = useState([]);


  const getData = () => {
    axios.get('http://192.168.8.143:8000/transactions/')
  .then(function (response) {
    // handle success
    console.log(response);
    setChartData(response.data);
    let data = response.data;
    let balance =  data?.filter((vl) => {
      return vl?.type == "BALANCE"
    });

    setBalanceData(balance)

    let savings =  data?.filter((vl) => {
      return vl?.type == "SAVING"
    })

    setSavingsData(savings);

    let loans =  data?.filter((vl) => {
      return vl?.type == "LOANS"
    });
    setLoansData(loans);

    let income =  data?.filter((vl) => {
      return vl?.type == "INCOME"
    });
    setIncomeData(income);

    let expenses =  data?.filter((vl) => {
      return vl?.type == "EXPENSES"
    })

    setExpensesData(expenses);

  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  
  }

  useEffect(() => {
    getData();
  }, [])



    console.log("Chart Data", ChartData);
...
...
export default Home;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source