Ask Your Question
1

What is the method to only render components on the client side in NextJS 13?

asked 2021-12-21 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-06 10:00:00 +0000

david gravatar image

The method to only render components on the client side in NextJS 13 is to use dynamic imports with the ssr: false option.

Here's an example:

import dynamic from 'next/dynamic';

const MyComponent = dynamic(() => import('../components/MyComponent'), {
  ssr: false,
});

function HomePage() {
  return (
    <div>
      <h1>Welcome to my NextJS app!</h1>
      <MyComponent />
    </div>
  );
}

export default HomePage;

In this example, the MyComponent is loaded dynamically, and the ssr: false option tells NextJS to only render it on the client side. This means that the component will not be included in the initial server-side rendering, but will instead be loaded and rendered on the client side after the page has loaded.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-21 11:00:00 +0000

Seen: 14 times

Last updated: Aug 06 '22