0.0.1 • Published 11 months ago

@phragon-react/use-create-context v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@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>
	);
}
0.0.1

11 months ago