Effect CommunityEC
Effect Communityβ€’3y agoβ€’
8 replies
sjm

Error: Service not found for ServiceConfigEff in a Preact app with hooks

I'm getting an error Error: Service not found for a service I have called ServiceConfigEff (slightly confusingly, but the ServiceConfig part pre-existed me using Effect).

I'm building the live version of this service dynamically when a function is called for now, as I'm trying to fit Effect into a fairly full-on preact app with hooks.

Could any part of this be what causes the issues?

The snipped where the error happens is here, which is inside a function which may possibly get called multiple times:

        if (serviceConfig && currentConfigurator && options) {
            const ServiceConfigEffLive = ServiceConfigEff.of({
                services: Effect.succeed(serviceConfig),
            });

            const allGoodsPending = state.goods.pending;
            if (!allGoodsPending) {
                dispatch(Goods.setPending(true));
                pipe(
                    Configuration.Good.fromProductOptions(currentConfigurator, options),
                    Effect.match({
                        onFailure: errs => {
                            dispatch(
                                Core.error({
                                    message: `all config products failed to fetch. Errors: ${JSON.stringify(
                                        errs,
                                    )}`,
                                    context: {
                                        type: 'global',
                                    },
                                }),
                            );
                            dispatch(Goods.setPending(false));
                            return null;
                        },
                        onSuccess: products => {
                            dispatch(Goods.setPending(false));
                            dispatch(Goods.setAllGoods(products));
                            return products;
                        },
                    }),
                    Effect.provideService(ServiceConfigEff, ServiceConfigEffLive),
                    Effect.runPromise,
                );
            }
        }
Was this page helpful?