import {Application} from "pixi.js"; const canvasRefPixi = useRef<PIXI.Application…
- User
import {Application} from "pixi.js";
const canvasRefPixi = useRef<PIXI.Application | null>(null); const draw = (trades: TradeItem[], camera: number) => { if (null === canvasRefPixi || !Array.isArray(trades)) return;
const app = canvasRefPixi.current; if (app) { const stage = app.stage; orderFeedDrawer.drawLinePixi( stage, canvasSize, trades, camera, cupParams.aggregatedPriceStep, cupParams.cellHeight, cupParams.quantityDivider, !settings.minQuantity ? 0 : parseFloat(settings.minQuantity), dpiScale, theme, ); }};
useEffect(() => { if (!workerRef.current) return; draw(event.data.trades, event.data.camera) }, [workerRef.current, canvasRef.current ]); return ( ); };
// // JSX element class does not support attributes because it does not have a 'props' property.ts(2607) 'Application' cannot be used as a JSX component. Its instance type 'Application' is not a valid JSX element. Type 'Application' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, and 2 more.ts(2786) (alias) class Application import Application Convenience class to create a new PixiJS application.
This class automatically creates the renderer, ticker and root container.
@example
import { Application, Sprite } from 'pixi.js';
// Create the application const app = new Application();
// Add the view to the DOM document.body.appendChild(app.view);
// ex, add display objects app.stage.addChild(Sprite.from('something.png'));
исправь ошибку
- Assistant
import { Application, Container } from "pixi.js";
const draw = (trades: TradeItem[], camera: number) => { if (!canvasRefPixi.current || !Array.isArray(trades)) return;
const stage = canvasRefPixi.current.stage; orderFeedDrawer.drawLinePixi( stage, canvasSize, trades, camera, cupParams.aggregatedPriceStep, cupParams.cellHeight, cupParams.quantityDivider, !settings.minQuantity ? 0 : parseFloat(settings.minQuantity), dpiScale, theme ); };
useEffect(() => { if (!workerRef.current) return; draw(event.data.trades, event.data.camera); }, [workerRef.current, canvasRef.current]);
return ( <div ref={canvasRefPixi} className={styles.canvas} style={{ width: canvasSize?.width, height: canvasSize?.height, }} > );
- User
Type 'Application | null' is not assignable to type 'HTMLDivElement | null'.
- Assistant
To fix this error, you can update the type declaration of
canvasRefPixitoHTMLDivElement | null. Here's an updated code snippet:import { Application, Container } from "pixi.js"; const canvasRefPixi = useRef<HTMLDivElement | null>(null); const draw = (trades: TradeItem[], camera: number) => { if (!canvasRefPixi.current || !Array.isArray(trades)) return; const stage = canvasRefPixi.current.stage; orderFeedDrawer.drawLinePixi( stage, canvasSize, trades, camera, cupParams.aggregatedPriceStep, cupParams.cellHeight, cupParams.quantityDivider, !settings.minQuantity ? 0 : parseFloat(settings.minQuantity), dpiScale, theme ); }; useEffect(() => { if (!workerRef.current) return; draw(event.data.trades, event.data.camera); }, [workerRef.current, canvasRef.current]); return ( <Box ref={containerRef} className={styles.canvasWrapper} scroll-block> <div ref={canvasRefPixi} className={styles.canvas} style={{ width: canvasSize?.width, height: canvasSize?.height, }} > <Container /> </div> </Box> ); - User
- Assistant
If you want to assign the PixiJS
Applicationinstance to therefof thedivelement, you can use a type assertion to override the type checking. Here's an updated code snippet:import { Application, Container } from "pixi.js"; const canvasRefPixi = useRef<HTMLDivElement | null>(null); const draw = (trades: TradeItem[], camera: number) => { if (!canvasRefPixi.current || !Array.isArray(trades)) return; const stage = canvasRefPixi.current.stage; orderFeedDrawer.drawLinePixi( stage, canvasSize, trades, camera, cupParams.aggregatedPriceStep, cupParams.cellHeight, cupParams.quantityDivider, !settings.minQuantity ? 0 : parseFloat(settings.minQuantity), dpiScale, theme ); }; useEffect(() => { if (!workerRef.current) return; draw(event.data.trades, event.data.camera); }, [workerRef.current, canvasRef.current]); return ( <Box ref={containerRef} className={styles.canvasWrapper} scroll-block> <div ref={(ref) => { canvasRefPixi.current = ref as HTMLDivElement; }} className={styles.canvas} style={{ width: canvasSize?.width, height: canvasSize?.height, }} > <Container /> </div> </Box> ); - User
drawLinePixi: ( stage: Container, canvasSize: CanvasSize, trades: TradeItem[], camera: number, aggregatedPriceStep: number, cupCellHeight: number, quantityDivider: number, minQuantity: number, dpiScale: number, theme: Theme, ) => { let startX = canvasSize.width - 10 * dpiScale; const fullHeightRowsCount = parseInt((canvasSize.height / cupCellHeight).toFixed(0)); const startY = (fullHeightRowsCount % 2 ? fullHeightRowsCount - 1 : fullHeightRowsCount) / 2 * cupCellHeight; const halfCupCellHeight = cupCellHeight / 2;
trades.forEach(trade => { const yModifier = (trade.price - (trade.price - (trade?.secondPrice || trade.price)) / 2 - camera) / aggregatedPriceStep * cupCellHeight + halfCupCellHeight; const width = 1.75 * clamp((trade.quantity / quantityDivider < minQuantity ? 0 : trade.radius), 5, 50) * dpiScale; const line = new Graphics(); line.lineStyle(2 * dpiScale, orderFeedOptions(theme).line.color); line.moveTo(startX - width / 2, startY - yModifier); line.lineTo(startX, startY - yModifier); stage.addChild?.(line); startX = startX - width; }); - Assistant
The issue seems to be related to the missing argument for
propswhen creating a new instance ofGraphicsfrom the PIXI.js library.To fix this error, you can modify the
drawLinePixifunction to include the requiredpropsargument for theGraphicsconstructor. Here's the updated code:import { Application, Container, Graphics } from "pixi.js"; const drawLinePixi = ( stage: Container, canvasSize: CanvasSize, trades: TradeItem[], camera: number, aggregatedPriceStep: number, cupCellHeight: number, quantityDivider: number, minQuantity: number, dpiScale: number, theme: Theme ) => { let startX = canvasSize.width - 10 * dpiScale; const fullHeightRowsCount = parseInt((canvasSize.height / cupCellHeight).toFixed(0)); const startY = (fullHeightRowsCount % 2 ? fullHeightRowsCount - 1 : fullHeightRowsCount) / 2 * cupCellHeight; const halfCupCellHeight = cupCellHeight / 2; trades.forEach((trade) => { const yModifier = (trade.price - (trade.price - (trade?.secondPrice || trade.price)) / 2 - camera) / aggregatedPriceStep * cupCellHeight + halfCupCellHeight; const width = 1.75 * clamp((trade.quantity / quantityDivider < minQuantity ? 0 : trade.radius), 5, 50) * dpiScale; const line = new Graphics({}); line.lineStyle(2 * dpiScale, orderFeedOptions(theme).line.color); line.moveTo(startX - width / 2, startY - yModifier); line.lineTo(startX, startY - yModifier); stage.addChild(line); startX = startX - width; }); }; - User
new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009) (alias) const Graphics: PixiComponent import Graphics
- Assistant
It seems that the error is related to an incorrect import statement for the
Graphicscomponent.Instead of importing
Graphicsdirectly frompixi.js, you can import it from thereact-pixilibrary, which provides the proper typings and construct signature for theGraphicscomponent.Here's the updated code:
import { Application, Container } from "pixi.js"; import { Graphics } from "@inlet/react-pixi"; // Rest of the code... const drawLinePixi = ( stage: Container, canvasSize: CanvasSize, trades: TradeItem[], camera: number, aggregatedPriceStep: number, cupCellHeight: number, quantityDivider: number, minQuantity: number, dpiScale: number, theme: Theme ) => { // Rest of the code... }; // Rest of the code...Make sure to install the
@inlet/react-pixipackage using npm or yarn before using it in your code.