0.1.0 #1
32
packages/reffuse/src/ReffuseContext.tsx
Normal file
32
packages/reffuse/src/ReffuseContext.tsx
Normal 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}
|
||||
/>
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
5
packages/reffuse/src/ReffuseRuntime.ts
Normal file
5
packages/reffuse/src/ReffuseRuntime.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Runtime } from "effect"
|
||||
import React from "react"
|
||||
|
||||
|
||||
export interface ReffuseRuntime<R> extends React.Context<Runtime.Runtime<R>> {}
|
||||
Reference in New Issue
Block a user