Created the VersionContext.jsx
This commit is contained in:
parent
b841a67ab7
commit
091a63759b
32
webui/src/common/contexts/Version/VersionContext.jsx
Normal file
32
webui/src/common/contexts/Version/VersionContext.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import {createContext, useEffect, useState} from "react";
|
||||
|
||||
export const VersionContext = createContext({});
|
||||
|
||||
export const VersionProvider = ({children}) => {
|
||||
|
||||
const [versions, setVersions] = useState(["1.20.1"]);
|
||||
|
||||
const updateVersions = () => {
|
||||
fetch("https://piston-meta.mojang.com/mc/game/version_manifest.json")
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
let versions = [];
|
||||
data.versions.forEach(version => {
|
||||
if (version.type === "release" && version.id.split(".")[1] > 8)
|
||||
versions.push(version.id);
|
||||
});
|
||||
versions.push("1.8.8");
|
||||
setVersions(versions);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateVersions();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<VersionContext.Provider value={versions}>
|
||||
{children}
|
||||
</VersionContext.Provider>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user