I was just going through a React project that uses hooks and function based components and came across the following peice of code, basically a component that looks like so:
const App = ({ init, isLoading }) => {
useEffect(() => {
init();
}, []);
const [isMobile, setisMobile] = useState(null);
console.log('isMobile');
console.log(isMobile);
// Set amount of items to show on slider based on the width of the element
const changeMobile = () => {
window.matchMedia('(max-width: 80em)').matches
? setisMobile(true)
: setisMobile(false);
};
useEffect(() => {
changeMobile();
window.addEventListener('resize', changeMobile);
return () => window.removeEventListener('resize', changeMobile);
}, []);
.........
};
The line of code i am talking about can be seen HERE too.
Usually i am used to seeing props being passed to function based components, but what i see here is very different , also where are these properties being passed from ? I.E. { init, isLoading } ?
Also because if i see how the <App /> component is being called HERE, i don't see any props being passed. So how exactly does this functional component get its parameters ?