UseContext
import { createContext } from 'react';
const Context = createContext('Default Value');
Mateusz Przybylski
import { createContext } from 'react';
const Context = createContext('Default Value');
function Main() {
const value = 'My Context Value';
return (
<Context.Provider value={value}>
<MyComponent />
</Context.Provider>
);
}
import { useContext } from 'react';
function MyComponent() {
const value = useContext(Context);
return <span>{value}</span>;
}