-2

As in RSC the React code will be on the server-side for various reasons mentioned HERE

I wonder if there is a way we can leverage the lifecycle and fetching APIs after the mounting point (For example update Or useEffects).

1 Answer 1

2

No.

From https://github.com/josephsavona/rfcs/blob/server-components/text/0000-server-components.md#capabilities--constraints-of-server-and-client-components :

Server Components: As a general rule, Server Components run once per request on the server, so they don’t have state and can’t use features that only exist on the client. Specifically, Server Components:

  • ❌ May not use state, because they execute (conceptually) only once per request, on the server. So useState() and useReducer() are not supported.
  • ❌ May not use rendering lifecycle (effects). So useEffect() and useLayoutEffect() are not supported.
  • ❌ May not use browser-only APIs such as the DOM (unless you polyfill them on the server).
  • ❌ May not use custom hooks that depend on state or effects, or utility functions that depend on browser-only APIs.
  • ✅ May use server-only data sources such as databases, internal (micro)services, filesystems, etc.
  • ✅ May render other Server Components, native elements (div, span, etc), or Client Components.

Server Hooks/Utilities: Developers may also create custom hooks or utility libraries that are designed for the server. All of the rules for Server Components apply. For example, one use-case for server hooks is to provide helpers for accessing server-side data sources.

Not the answer you're looking for? Browse other questions tagged or ask your own question.