Compare commits
3 Commits
972986241c
...
b50255ded2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b50255ded2 | ||
|
|
03f0b623ed | ||
|
|
fb6d803723 |
@@ -36,12 +36,7 @@ function makeProvider<R>(Context: React.Context<Context.Context<R>>): ReactProvi
|
|||||||
Runtime.runSync(runtime),
|
Runtime.runSync(runtime),
|
||||||
), [props.layer, runtime])
|
), [props.layer, runtime])
|
||||||
|
|
||||||
return (
|
return React.createElement(Context, { ...props, value })
|
||||||
<Context
|
|
||||||
{...props}
|
|
||||||
value={value}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +52,7 @@ function makeAsyncProvider<R>(Context: React.Context<Context.Context<R>>): Async
|
|||||||
readonly children?: React.ReactNode
|
readonly children?: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
const value = React.use(promise)
|
const value = React.use(promise)
|
||||||
|
return React.createElement(Context, { value, children })
|
||||||
return (
|
|
||||||
<Context
|
|
||||||
value={value}
|
|
||||||
children={children}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return function ReffuseContextAsyncReactProvider(props) {
|
return function ReffuseContextAsyncReactProvider(props) {
|
||||||
@@ -74,14 +63,8 @@ function makeAsyncProvider<R>(Context: React.Context<Context.Context<R>>): Async
|
|||||||
Runtime.runPromise(runtime),
|
Runtime.runPromise(runtime),
|
||||||
), [props.layer, runtime])
|
), [props.layer, runtime])
|
||||||
|
|
||||||
return (
|
const inner = React.createElement(Inner, { ...props, promise })
|
||||||
<React.Suspense fallback={props.fallback}>
|
return React.createElement(React.Suspense, { children: inner, fallback: props.fallback })
|
||||||
<Inner
|
|
||||||
{...props}
|
|
||||||
promise={promise}
|
|
||||||
/>
|
|
||||||
</React.Suspense>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
15
packages/reffuse/src/ReffuseRuntime.ts
Normal file
15
packages/reffuse/src/ReffuseRuntime.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Runtime } from "effect"
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
|
||||||
|
export const Context = React.createContext<Runtime.Runtime<never>>(null!)
|
||||||
|
|
||||||
|
export const Provider = (props: {
|
||||||
|
readonly children?: React.ReactNode
|
||||||
|
}) => React.createElement(Context, {
|
||||||
|
...props,
|
||||||
|
value: Runtime.defaultRuntime,
|
||||||
|
})
|
||||||
|
Provider.displayName = "ReffuseRuntimeReactProvider" as const
|
||||||
|
|
||||||
|
export const useRuntime = () => React.useContext(Context)
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { Runtime } from "effect"
|
|
||||||
import * as React from "react"
|
|
||||||
|
|
||||||
|
|
||||||
export const Context = React.createContext<Runtime.Runtime<never>>(null!)
|
|
||||||
|
|
||||||
export const Provider = (props: { readonly children?: React.ReactNode }) => (
|
|
||||||
<Context
|
|
||||||
{...props}
|
|
||||||
value={Runtime.defaultRuntime}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
Provider.displayName = "ReffuseRuntimeReactProvider"
|
|
||||||
|
|
||||||
export const useRuntime = () => React.useContext(Context)
|
|
||||||
Reference in New Issue
Block a user