@phragon-react/use-create-context
v0.0.1
Published
Helper hooks for react createContext function and useContext hook
Downloads
1
Readme
@phragon-react/use-create-context
Helper hooks for react createContext function and useContext hook
❯ Install
$ npm install --save @phragon-react/use-create-context
Usage
import { createContext, createStrictContext } from "@phragon-react/use-create-context";
const [Provider, useContext] = createContext();
const [StrictProvider, useStrictContext] = createStrictContext();
function Foo() {
return (
<Provider value={"test"}>
<Bar />
</Provider>
);
}
function FooStrict() {
return (
<StrictProvider value={"test"}>
{/* Successfull render, <Bar /> is null */}
<Bar />
<BarStrict />
</StrictProvider>
);
}
function FooError() {
return (
<>
{/* Successfull render, <Bar /> is null */}
<Bar />
{/* Render failed */}
<BarStrict />
</>
);
}
function Bar() {
const context = useContext();
return (
<div>{context}</div>
);
}
function BarStrict() {
const context = useStrictContext();
return (
<div>{context}</div>
);
}