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),
|
||||
), [props.layer, runtime])
|
||||
|
||||
return (
|
||||
<Context
|
||||
{...props}
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
return React.createElement(Context, { ...props, value })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +52,7 @@ function makeAsyncProvider<R>(Context: React.Context<Context.Context<R>>): Async
|
||||
readonly children?: React.ReactNode
|
||||
}) {
|
||||
const value = React.use(promise)
|
||||
|
||||
return (
|
||||
<Context
|
||||
value={value}
|
||||
children={children}
|
||||
/>
|
||||
)
|
||||
return React.createElement(Context, { value, children })
|
||||
}
|
||||
|
||||
return function ReffuseContextAsyncReactProvider(props) {
|
||||
@@ -74,14 +63,8 @@ function makeAsyncProvider<R>(Context: React.Context<Context.Context<R>>): Async
|
||||
Runtime.runPromise(runtime),
|
||||
), [props.layer, runtime])
|
||||
|
||||
return (
|
||||
<React.Suspense fallback={props.fallback}>
|
||||
<Inner
|
||||
{...props}
|
||||
promise={promise}
|
||||
/>
|
||||
</React.Suspense>
|
||||
)
|
||||
const inner = React.createElement(Inner, { ...props, promise })
|
||||
return React.createElement(React.Suspense, { children: inner, fallback: props.fallback })
|
||||
}
|
||||
}
|
||||
|
||||
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