import { useState, useContext, createContext } from "https://esm.sh/react";
import ReactDOM from "https://esm.sh/react-dom";
const initialState = {
state: 'Some data...'
};
const CustomContext = createContext(initialState);
function App() {
return (
<CustomContext.Provider value={initialState}>
<ChildA />
</CustomContext.Provider>
)
}
function ChildA(props) {
return (
<ChildB />
);
}
function ChildB(props) {
const {state} = useContext(CustomContext);
return (
<div>{state}</div>
);
}
ReactDOM.render(<App />, document.querySelector("#app"));
View Compiled