Effect CommunityEC
Effect Community3y ago
7 replies
Ken

Struggling with Typing Function for Dependency Injection in effect-ts with React

Hello everyone!

In my current use-case I intend to use effect with react only for dependency injection through runtime, and I struggle with typing the function that accepts tuple/record of tags and returns services.

export type WebRuntime = Runtime.Runtime<Service1 | Service2 | ...>

export declare function useRuntime():WebRuntime

export const useEnvrionment = (args) => {
 const runtime = useRuntime();
 return pipe(
   Effect.all(args),
   Runtime.runSync(runtime)
 )
}


intended usage:

const deps = {
 Link: Link.tag,
 config: AppConfig.tag
}
const Component = () => {
  const {Link, config} = useEnvironment(deps)

  return <Link href={`${config.something}`}> Whatever </Link>
}
Was this page helpful?