mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
Replace ConnectionBauble Class Component with Functional one
This commit is contained in:
parent
88d8f13847
commit
725fb05bb3
@ -1,41 +1,21 @@
|
||||
import React from "react";
|
||||
|
||||
interface baubleState {
|
||||
connection: boolean;
|
||||
callback: () => boolean;
|
||||
}
|
||||
import React, {useState, useEffect } from "react";
|
||||
|
||||
interface baubleProps {
|
||||
callback: () => boolean;
|
||||
}
|
||||
|
||||
export class ConnectionBauble extends React.Component<baubleProps> {
|
||||
timerID: NodeJS.Timer;
|
||||
state: baubleState;
|
||||
export const ConnectionBauble = (props: baubleProps): React.ReactElement => {
|
||||
const [connection, setConnection] = useState(props.callback())
|
||||
|
||||
constructor(props: baubleProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
connection: props.callback(),
|
||||
callback: props.callback,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount(): void {
|
||||
this.timerID = setInterval(() => this.tick(), 1000);
|
||||
}
|
||||
|
||||
componentWillUnmount(): void {
|
||||
clearInterval(this.timerID);
|
||||
}
|
||||
|
||||
tick(): void {
|
||||
this.setState({
|
||||
connection: this.state.callback(),
|
||||
useEffect(() => {
|
||||
setInterval(() => {
|
||||
setConnection(props.callback());
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
render(): string {
|
||||
return this.state.connection ? "Connected" : "Disconnected";
|
||||
}
|
||||
return (
|
||||
<div className="ConnectionBauble">
|
||||
{connection? "Connected" : "Disconnected"}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import { GameOptionsTab } from "../GameOptionsTab";
|
||||
import { GameOptionsPage } from "./GameOptionsPage";
|
||||
import { OptionsSlider } from "./OptionsSlider";
|
||||
import Button from "@mui/material/Button";
|
||||
import { ConnectionBauble } from "./ConnectionBauble";
|
||||
import { ConnectionBaub, ConnectionBauble } from "./ConnectionBauble";
|
||||
|
||||
interface IProps {
|
||||
currentTab: GameOptionsTab;
|
||||
|
Loading…
Reference in New Issue
Block a user