Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Recoil.js #65

Open
joseananio opened this issue Dec 24, 2020 · 0 comments
Open

Support for Recoil.js #65

joseananio opened this issue Dec 24, 2020 · 0 comments

Comments

@joseananio
Copy link

Any chance recoil will be supported?
It has relatively simpler interface than redux so I expect a plugin to be easy to whip up.

I have tried unsuccessfully to adapt the pawjs-redux plugin with this error:

A Server error has occurred
Error Stack:
This component must be used inside a <RecoilRoot> component.


Error: This component must be used inside a <RecoilRoot> component.
    at Object.notInAContext (webpack-internal:///./node_modules/recoil/es/recoil.js:1546:9)
    at getRecoilValueAsLoadable (webpack-internal:///./node_modules/recoil/es/recoil.js:1312:2315)
    at useRecoilValueLoadable_LEGACY (webpack-internal:///./node_modules/recoil/es/recoil.js:2554:10)
    at useRecoilValueLoadable (webpack-internal:///./node_modules/recoil/es/recoil.js:2568:12)
    at useRecoilValue (webpack-internal:///./node_modules/recoil/es/recoil.js:2586:18)
    at useRecoilState (webpack-internal:///./node_modules/recoil/es/recoil.js:2638:11)
    at TT (webpack-internal:///./src/components/auth/register.js:39:64)
    at renderWithHooks (webpack-internal:///./node_modules/@hot-loader/react-dom/cjs/react-dom.development.js:14804:14)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/@hot-loader/react-dom/cjs/react-dom.development.js:17483:7)
    at beginWork (webpack-internal:///./node_modules/@hot-loader/react-dom/cjs/react-dom.development.js:18597:8)


Component Stack:

    in TT (created by Context.Consumer)
    in _default
    in ErrorBoundary
    in Unknown (created by Context.Consumer)
    in withRouter() (created by Context.Consumer)
    in Route
    in Switch
    in ErrorBoundary
    in App (created by HotExportedApp)
    in AppContainer (created by HotExportedApp)
    in HotExportedApp
    in RecoilRoot
    in Router
    in ErrorBoundary

Here's my client.js in the plugin:

export default class RecoilClient {
  constructor() {
    this.hooks = {
      recoilInit: new AsyncSeriesHook(["state"]),
    };
  }

  apply(clientHandler) {
    clientHandler.hooks.beforeLoadData.tapPromise(
      "AddRecoilProvider",
      async (setParams, getParams) => {
        const state = {
          setInitialState: (iState) => {
            // initialState = cloneDeep(iState);
          },
          getInitialState: () => {
            // if (typeof initialState === 'undefined') return {};
            // return cloneDeep(initialState);
            return {};
          },
        };
        await new Promise((r) => this.hooks.recoilInit.callAsync(state, r));
      }
    );

    clientHandler.hooks.beforeRender.tapPromise(
      "AddRecoilProvider",
      async (app) => {
        // eslint-disable-next-line
        app.children = <RecoilRoot>{app.children}</RecoilRoot>;
      }
    );
  }
}

It works when I add the recoil package directly to pawjs like below so I believe the issue is with plugin handling

// src/client/handler.tsx
...
const children = (
      // eslint-disable-next-line react/jsx-props-no-spreading
      <components.appRouter basename={this.options.env.appRootUrl} {...routerParams}>
        <RecoilRoot>{appRoutes.renderedRoutes}</RecoilRoot>
      </components.appRouter>
    );
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant