jspreadsheet / ce

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.
https://bossanova.uk/jspreadsheet/v4
MIT License
6.66k stars 820 forks source link

Next.js Reference Error to Window #1598

Closed munozr1 closed 1 year ago

munozr1 commented 1 year ago

I am building a next.js 13 project using the library and ran into a reference error. I have tried common things like putting the initialization in a useEffect to guarantee that it runs client side.

Here is the troublesome component: https://stackblitz.com/edit/nextjs-9h6npb?file=pages/index.js

thakn you.

munozr1 commented 1 year ago

fix is to dynamically load the library:

`useEffect(() => { const loadJSpreadsheet = async () => { const jspreadsheet = await import("jspreadsheet-ce"); const options: JSpreadsheetOptions = { data: [[]], minDimensions: [1, 1], columns: [ { type: 'text',width: 130, title: 'Date' },{ type: 'text',width: 130, title: 'First Name' }, {type: 'text',width: 130, title: 'Last Name'}, {type: 'text',width: 130, title: 'DOB'}, { type: 'text',width: 130, title: 'Boxes Issued' }, {type: 'text',width: 130, title: 'Issuer Initials'}, {type: 'text',width: 130, title: 'Lot No'}, { type: 'text',width: 130, title: 'Quantity' }, {type: 'text',width: 130, title: 'Count'}, {type: 'text',width: 130, title: 'Remark'}], }; //@ts-ignore if (!jRef.current.jspreadsheet && typeof window !== undefined) { //@ts-ignore jspreadsheet.default(jRef.current, options); } }; if(jRef.current){ loadJSpreadsheet(); }

});`