We need to find greatest number that divide both 30 and 42. That number is also called "greatest common divisor". Numbers that divide both 30 and 42 are 1,2,3 and 6.
Therefore greatest number of identical baskets is 6. Each will consist 30/6=5 sandwiches and 42/6=7 cookies.