Prop drilling occurs when you need to pass data from a higher-level component down to a lower-level component that is several layers deep in the component tree. This often leads to the following issues:
import React, { useState } from 'react';
// LightBulb Component
const LightBulb = ({ isOn }) => {
return <div>The light is {isOn ? 'ON' : 'OFF'}</div>;
};
// LightSwitch Component
const LightSwitch = ({ toggleLight }) => {
return <button onClick={toggleLight}>Toggle Light</button>;
};
// App Component
const App = () => {
const [isLightOn, setIsLightOn] = useState(false);
const toggleLight = () => {
setIsLightOn((prev) => !prev);
};
return (
<div>
<LightBulb isOn={isLightOn} />
<LightSwitch toggleLight={toggleLight} />
</div>
);
};
export default App;

