mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +02:00
DOCUMENTATION: Add starter react documentation (#1888)
This commit is contained in:
committed by
GitHub
parent
85fa15c5a5
commit
e3eb08470b
@@ -47,6 +47,7 @@
|
||||
- [Learn to program](programming/learn.md)
|
||||
- [Remote API](programming/remote_api.md)
|
||||
- [Game frozen or stuck?](programming/game_frozen.md)
|
||||
- [React](programming/react.md)
|
||||
- [Tools & Resources](help/tools_and_resources.md)
|
||||
- [Changelog](changelog.md)
|
||||
- [Changelog - Legacy v1](changelog-v1.md)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# How to use React in game
|
||||
|
||||
Since v2.7.0, Bitburner supports React and TypeScript out of the box. You can use the jsx syntax inside `.jsx` and `.tsx` files.
|
||||
|
||||
## Example
|
||||
|
||||
Use `ns.printRaw` and `ns.tprintRaw` to render React elements in the logs and terminal.
|
||||
|
||||
```tsx
|
||||
// timer.tsx
|
||||
function Timer() {
|
||||
const [seconds, setSeconds] = React.useState(0);
|
||||
|
||||
React.useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setSeconds((seconds) => seconds + 1);
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return <div>Seconds: {seconds}</div>;
|
||||
}
|
||||
|
||||
export async function main(ns: NS) {
|
||||
ns.tail();
|
||||
ns.printRaw(<Timer />);
|
||||
await ns.asleep(10000);
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user