41 - Usecontext Hook
41 - Usecontext Hook
useContext
Hook
PRESENTER: MOHAMMAD ADIL
REACT
Humble Request REACT
Techno Verse YT
Heavenly Delicious
REACT
Props
A
REACT
APP Component Name = Adil
Props
A
Props
B
APP Component Name = Adil REACT
Props
A
Prop Drilling
Props
B
Props
useContext C
React Context REACT
• State should be held by the highest parent component in the stack that
requires access to the state.
• To do this without Context, we will need to pass the state as "props"
through each nested component. This is called "prop drilling".
function Component1() { function Component2({ user }) {
const [user, setUser] = useState(“Adil"); return (
<>
return ( <h1>Component 2</h1>
<> <Component3 user={user} />
<h1>{`Hello ${user}!`}</h1> </>
<Component2 user={user} /> );
</> }
);
}
function Component3({ user }) {
return (
<>
<h1>Component 3</h1>
<Component4 user={user} />
</>
);
}