DEV Community

Discussion on: Architecting Frontend Projects To Scale

bennaceurhichem profile image
Bennaceur Hichem

it doesn't work for me due to this issue

TypeError: undefined is not an object (evaluating '_apiProducts.apiProducts.getAll')

I think the synchronisation is not good enough how can I solve this ?

mmcshinsky profile image
Michael McShinsky Author

Hi Bennaceur! Can you provide more context of what your code looks like? Typically the underscore in a function denotes an internal function to the component. You'll probably have something more like:

function _apiProducts () {
  apiProducts.getAll().then(res => {}).catch(err => {})

Enter fullscreen mode Exit fullscreen mode

...but I don't know what your code looks like.

bennaceurhichem profile image
Bennaceur Hichem • Edited on

I'm working with this woocommerce api and I want to organize my api calls like what you did sir,
thuis my code in the component where I ade the call

import { apiProducts } from '../services/api/apiProducts';
import React,{useState,useEffect} from 'react'
import { View, Text, StyleSheet,Button } from 'react-native'
import { render } from 'react-dom'

export default function Products() {
  const [Products, setProducts] = useState([]);

  useEffect(() => {
  }, []);
  function  getProducts(){
  // if(apiProducts)
     apiProducts.getAll().then((res) => {
      let arr = parseProducts(;
    .catch( (err)=> console.log("ERROR"+err));

  function parseProducts(Products) {
    return => {
      // Parse Product information
      return Product;

  function _createProduct(Product) { => {
      // state logic

  function _updateProduct(Product) {
    apiProducts.patch(Product).then((res) => {
      // state logic

  function _removeProduct(id) {
    apiProducts.remove(id).then((res) => {
      // state logic

  return (

      { => (

  onPress={() => 

  accessibilityLabel="Learn more about this purple button"

Enter fullscreen mode Exit fullscreen mode

The major change is that I use the WoocommerceAPI instead of axios. The instatiation of the connection with the woocomme'rce api works like mentioned in docs here :

so instead of axios I used WooCommerceAPI