Hello dear Webix community,
I want to integrate the Spreadsheet-ComplexWidget in a React app with Typescript.
My dependencies are as simple as possible:
"@xbs/spreadsheet": "^10.2.1",
"@xbs/webix-pro": "^10.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
When I try to include a Spreadsheet View, I get the following error message:
spreadsheet.js:355 Uncaught ReferenceError: webix is not defined
at spreadsheet.js:355:2
at spreadsheet.js:10:65
at node_modules/@xbs/spreadsheet/spreadsheet.js (spreadsheet.js:13:1)
at __require (chunk-76J2PTFD.js?v=1b8c8e08:3:50)
at spreadsheet.js:17800:3
My react component is defined as follows:
import Webix from "./Webix.tsx";
import {ui} from "@xbs/webix-pro";
import '@xbs/spreadsheet/spreadsheet.min.css'
import '@xbs/spreadsheet/spreadsheet.js'
function webixConfig(): ui.layoutConfig{
return {
cols: [
{ view:"spreadsheet", id: "spreadsheet-123"}
]
};
}
export default function WebixView() {
return (
<div style={{height: "100vh", width: '100vw'}}>
<Webix ui={webixConfig()}/>
</div>
)
}
The used ‘Webix’ component has been taken from the Webix-React integration example. I had to modify it slightly in order to support a newer version of react and avoid deprecations.
Non-complex widgets work without any errors.
Does anybody have a clue and may give me some advice?
In case that it may be important i’m providing the source of the ‘Webix’ component as well:
import {Component, createRef} from 'react';
import '@xbs/webix-pro/webix.min.css'
import {ui} from "@xbs/webix-pro";
export type WebixProperties = {
ui: ui.baseviewConfig,
data?: any,
select?: any
}
class Webix<S> extends Component<WebixProperties, S> {
private ref = createRef<HTMLDivElement>();
private ui: ui.baseview | null = null;
render() {
return (
<div style={{height: '100%', width: '100%', padding: '0px', margin:'0px', border: 'none', display: 'block'}} ref={this.ref}></div>
);
}
public setWebixData(data: any){
const ui: any = this.ui;
if (ui.setValues)
ui.setValues(data);
else if (ui.parse)
ui.parse(data)
else if (ui.setValue)
ui.setValue(data);
}
public componentWillUnmount(){
if(this.ui){
this.ui.destructor();
this.ui = null;
}
}
public componentDidUpdate(props: WebixProperties){
if (props.data)
this.setWebixData(props.data);
if (props.select && this.ui){
const ui:any = this.ui;
ui.select(props.select);
}
}
public componentDidMount(){
this.ui = ui(
this.props.ui,
this.ref.current!
);
this.componentDidUpdate(this.props);
}
}
export default Webix;