Trying to send hook On Press with navigate on the end of the function ,and get undefined when receives on the other page

Viewed 13

this is the function act:

    const categoryHandler=(item)=>{
    
    if(item.category==='Burger'){
       setDataForCategoryPage(catBurger);
        
    }
    else if(item.category==='Pizza'){
        setDataForCategoryPage(catPizza);
    }
    else if(item.category==='Sushi'){
        setDataForCategoryPage(catSushi);
    }
    else{
        setDataForCategoryPage(catMiddleEast);
    }
    
    navigation.navigate('CategoryRes',{item},{dataForCategoryPage},{isLoadingCategory})
}

trying to pass dataForCategoryPage

here received the hook

const CategoryRes=({navigation,route})=>{

const [data,setData]=useState([]);
const{item,isLoadingCategory,dataForCategoryPage}=route.params;




    

and getting the undefined, what I need to do?

1 Answers

I managed to fix it, first i pass in the wrong way parameters in the navigation, its should be:

 navigation.navigate('CategoryRes',{data:data,item,isLoadingCategory})






    const categoryHandler=(item)=>{
    let data=[]

    if(item.category==='Burger'){
        data=catBurger;
       setDataForCategoryPage(data);
        
    }
    else if(item.category==='Pizza'){
        data=catBurger;
        setDataForCategoryPage(data);
    }
    else if(item.category==='Sushi'){
        data=catBurger;
        setDataForCategoryPage(data);
    }
    else{
        data=catBurger;
        setDataForCategoryPage(data);
        
    }
    navigation.navigate('CategoryRes',{data:data,item,isLoadingCategory})
   
}

A bit like a band-aid but its work if some one have better solution ,I will glad to hear.

Related