Files
bun.sh/integration/snippets/react-context-value-func.tsx
2021-10-06 19:21:26 -07:00

35 lines
668 B
TypeScript

import React from "react";
const Context = React.createContext({});
const ContextProvider = ({ children }) => {
const [cb, setCB] = React.useState(function () {});
const foo = true;
return <Context.Provider value={cb}>{children(foo)}</Context.Provider>;
};
const ContextValue = ({}) => (
<Context.Consumer>
{(foo) => {
if (foo) {
return <div>Worked!</div>;
}
throw `Value "${foo}"" should be true`;
}}
</Context.Consumer>
);
const TestComponent = () => (
<ContextProvider>
<ContextValue />
</ContextProvider>
);
export function test() {
const foo = <TestComponent />;
return testDone(import.meta.url);
}