DEV Community

Discussion on: My approach to SSR and useEffect - discussion

Collapse
 
vengeurmasque78 profile image
TheVengeurMasque

From what I understand in Dan's abramov demo, the component wrapped within suspense is not rendered. If you inspect the page, you won't see any html.
React 18 does not have to wait for all promises to resolve.
When a promise resolve, it will then render the code server side and "inject it" on the client. That's the beauty of it. It solves the waterfall issue if I understood correctly.
Though Dan abramov said they have not implemented the data fetching mechanism.
Does useSEE fetch data twice (server + client) ? From what you wrote, you said that data will be available in the global context.
So I guess we have to check if data exist in the global context we fetch or we don't
Something like

const [data] = useSSE(
    {},
    "my_article",
    () => {
      if (!fetchedData) {
      return fetch('http://articles-api.example.com').then((res) => res.json());
      }
    },
    []
  );
Enter fullscreen mode Exit fullscreen mode