in react i try to send a function as props but it doesn't work

33 views Asked by At

I am trying to make a component that receives props from other components in order to generate a mui table, I send my function as a prop and it works correctly and I even check the network to see that the api works and everything is correct, but my variable is always undefined, I share my code maybe there is something I'm not seeing

findAllComplementosFilter(searchText, complementos.page, complementos.rowsPerPage); 

This is how it sent the props to the component

<CustomMuiDataTable
                title={'Complementos de Pago'}
                //data={complementos.data}
                columns={columnsComplemento}
               // customOptions={customOptions}
               fetchData={findAllComplementosFilter}
              />

This way I receive it and use it but my newData variable is always undifined

const CustomMuiDataTable = ({ title, columns, fetchData })
const petitionData = async () => {
  try{
    const newData = await fetchData(
      data.searchText,
      data.page,
      data.rowsPerPage
    );  
    
    if (newData) {
      const fetchAndSetData = {
        data: newData.content,
        count: newData.totalElements,
        page: newData.pageable ? newData.pageable.pageNumber : null,
        rowsPerPage: newData.pageable ? newData.pageable.pageSize : null,
      };
      setData(fetchAndSetData);
    }
    console.log("data", newData);
  }catch(err){
    console.error("error ",err)
  }
  };

try to include the try catch to see if there was a more specific error but it is not marking one

0

There are 0 answers