ReffuseContext
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-01-15 00:16:57 +01:00
parent ec264e0381
commit 9f08894b61
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { Context, Layer } from "effect"
import React from "react"
export interface ReffuseContext<R> {
readonly Context: React.Context<Context.Context<R>>
readonly Provider: ReffuseContextReactProvider<R>
}
export type ReffuseContextReactProvider<R> = React.FC<{
readonly layer: Layer.Layer<R, unknown>
readonly children?: React.ReactNode
}>
export type R<T> = T extends ReffuseContext<infer R> ? R : never
export function make<R>(): ReffuseContext<R> {
const Context = React.createContext<Context.Context<R>>(null!)
return {
Context,
Provider: function ReffuseContextReactProvider(props) {
return (
<Context
{...props}
/>
)
},
}
}

View File

@@ -0,0 +1,5 @@
import type { Runtime } from "effect"
import React from "react"
export interface ReffuseRuntime<R> extends React.Context<Runtime.Runtime<R>> {}