因为知道NextJS正在使用服务器端渲染,所以我想使用SurveyJs,但是surveyJS使用了一些必须在客户端执行的函数。在我的例子中,我想使用StylesManager.applyTheme,但它抛出了ReferenceError: document is not defined的服务器错误
在客户端执行applyTheme函数有什么可行的方法吗?
发布于 2020-12-17 20:45:10
您可以创建一个使用外部函数来应用此主题的useEffect钩子来实现此目的:
import {useEffect} from 'react'
useEffect(() => {
const newSurveyCreator = new SurveyJSCreator.SurveyCreator('surveyCreatorContainer', surveyCreatorConfig);
newSurveyCreator.saveSurveyFunc = function() {
console.log(this);
console.log(this && this.text);
};
updateSurveyCreator(newSurveyCreator);
}, []);https://stackoverflow.com/questions/65340838
复制相似问题