Skip to content

Potential issue page HOC #4

@Yuant-tobing

Description

@Yuant-tobing

an error will appear where the window object is not defined, I'm a guest this may be the result of server side rendering

page.js

    let initData = null;
    if (staticContext) {
      initData = staticContext.data;
    } else if (window.__ROUTE_DATA__) {
      initData = window.__ROUTE_DATA__;
      delete window.__ROUTE_DATA__;
    }

It would be better if the above syntax was put into the effects func.
initialData will never change when navigating to another route on the client side, because window.ROUTE_DATA still stores data on the first page request, so each route will get the same data.

    if (!staticContext) {
      useEffect(() => {
        if (!initData) {
          fetch(`data${location.pathname}`)
            .then(r => r.json())
            .then(setPageData);
        }
      }, [location]);
    }

according to react hook rules, it might be better to put that condition inside our effect hook
https://reactjs.org/docs/hooks-rules.html

const page = (WrappedComponent) =>
  ({ staticContext })

Please, make a HOC page support react-router-dom v6 (beta)

Thanks, sorry my bad english

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions