useContext react

import React from 'react' import ReactDOM from 'react-dom' import { useContext } from 'react' const konteks = React.createContext(null); function components(){ return( <konteks.Provider value="hello world"> <MyComponent /> </konteks.Provider> ); } function MyComponent(){ const getcontext = useContext(konteks); return( <div>{getcontext}</div> ); } const body = ReactDOM.createRoot(document.getElementById("body")); body.render(<MyComponent/>); I already know the use of useContext, where we can pass data to other components,But I'm still confused regarding the implementation and the code above doesn't work, where is the error?
2 Replies
savvystrider15
savvystrider1513mo ago
konteks should be Konteks (capitalize first letter): https://react.dev/reference/react/createContext#provider
createContext – React
The library for web and native user interfaces
Abrar
Abrar13mo ago
Thanks for that sir
Want results from more Discord servers?
Add your server