Tracker made in React for keeping track of HP and MP and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.2 KiB

import React, {useEffect, useState} from 'react';
import './App.css';
import {Container} from "react-bootstrap";
import {Character, CharacterStatus} from "./CharacterStatus";
export interface PastState {
// This is the timestamp of the change that exited this state.
readonly timestampMs: number
// This is the list of actions that changed this state.
}
function useJson<T>(url: string): T | null {
const [data, setData] = useState<T|null>(null);
useEffect(() => {
let ignore = false;
fetch(url)
.then(response => response.json() as T)
.then(json => {
if (!ignore) {
setData(json);
}
});
return () => {
ignore = true;
};
}, [url]);
return data as T|null;
}
function App() {
const state = useJson<SavedState>("/api/current.json")
return <React.Fragment>
<Container fluid>
{state && state.characters.map((character) =>
<CharacterStatus
key={character.id}
character={character}
active={character.id === state.conflict?.activeCharacterId} />)}
</Container>
</React.Fragment>;
}
export default App;