surveyjs / surveyjs_react_quickstart

SurveyJS + React Quickstart Template
http://surveyjs.io
140 stars 78 forks source link

Does this work with NextJS? #25

Closed kamal-choudhary closed 2 years ago

kamal-choudhary commented 3 years ago

Hi, thank you for the awesome quickstart application.

I am trying to convert this quickstart application from React to NextJS.

But, I have been failing again and again.

Now, I am wondering that whether it is possible that it can work with NextJS or not?

Because this SurveyJS library is a browser-side library. While NextJS is often used for severe side rendering or static generation.

I'll be very thankful to you for your help.

tsv2013 commented 3 years ago

SurveyJS is a client-side JavaScript library. At this moment it doesn't support server-side rendering.

kamal-choudhary commented 3 years ago

Thank you for the quick response.

So, it means that we can't use it with NextJS? Or is there any workaround to make it work with NextJS?

tsv2013 commented 3 years ago

I'm not an expert in NextJS. Probably you can disable SSR and this will work for you.

kamal-choudhary commented 3 years ago

okay, I got it. Thank you very much for your time!!!

kamal-choudhary commented 2 years ago

Posting this solution for future readers.

This is how I am using this library in the NextJS.

pages/survey-view.js

import React from 'react';
import dynamic from 'next/dynamic';
import PageLoader from './PageLoader';   // Loading Spinner

const Survey = dynamic(() => import('./SurveyView'), {
  loading: () => <PageLoader />,
  ssr: false,
});

export default function SurveyPage() {
  return <Survey />;
}