I’d like to use PixiJS and Next.js to create a screen-fitting optimal scale ratio stage. I’m aware of @pixi/react
, but I want to create a game and it’d be inefficient to re-render the stage everytime an Isogenic entity spawns, unspawns, re-positions and rotates, considering there might be hundreds of entities.
I’ve tried running this:
function createElement() {
const element = document.createElement('span');
element.innerText = 'span';
return element;
}
export default function App() {
return (
<h1>Interpolated: {createElement()}</h1>
);
}
Got:
Objects are not valid as a React child (found: [object HTMLSpanElement]).
The PixiJS getting started page contains this code:
// The application will create a renderer using WebGL, if possible,
// with a fallback to a canvas render. It will also setup the ticker
// and the root stage PIXI.Container
const app = new Application();
// The application will create a canvas element for you that you
// can then insert into the DOM
document.body.appendChild(app.view);
So interpolating the HTML text would not work.
2
Answers
I've used the
useEffect
hook and a disjoint state at the moment to activate the level display in PixiJS.Use
dangerouslySetInnerHTML