Add jsx support, readme instructions for using React

main
Pwntheon 10 months ago
parent d92ca5f82e
commit 59d936d19b

@ -70,3 +70,27 @@ import { someFunction } from "main";
### Debugging
For debugging bitburner on Steam you will need to enable a remote debugging port. This can be done by rightclicking bitburner in your Steam library and selecting properties. There you need to add `--remote-debugging-port=9222` [Thanks @DarkMio]
### Using React
Some `ns` functions, like [`ns.printRaw()`](https://github.com/bitburner-official/bitburner-src/blob/dev/markdown/bitburner.ns.printraw.md) allows you to render React components into the game interface.
The game already exposes the `React` and `ReactDOM` objects globally, but in order to work with strongly typed versions in `.ts` files, you can use the included typings. To do this, use the following import:
`import React, { ReactDOM } from '@react'`
Support for jsx is also included, so if you use the `.tsx` file ending, you can do something like:
```ts
import { NS } from '@ns';
import React from '@react';
interface IMyContentProps {
name: string
}
const MyContent = ({name}: IMyContentProps) => <span>Hello {name}</span>;
export default async function main(ns: NS){
ns.printRaw(<MyContent name="Your name"></MyContent>);
}
```

@ -14,6 +14,7 @@
"outDir": "dist/",
"baseUrl": "src/",
"allowJs": true,
"jsx": "react",
"paths": {
"/*": ["*"],
"@ns": ["../NetscriptDefinitions.d.ts"],

Loading…
Cancel
Save