Created the ChannelContext.jsx
This commit is contained in:
parent
491da06147
commit
da7a6785d6
@ -0,0 +1,32 @@
|
|||||||
|
import {createContext, useEffect, useState} from "react";
|
||||||
|
import {jsonRequest} from "@/common/util/RequestUtil.js";
|
||||||
|
import {useParams} from "react-router-dom";
|
||||||
|
|
||||||
|
export const ChannelContext = createContext({});
|
||||||
|
|
||||||
|
|
||||||
|
export const ChannelProvider = ({children}) => {
|
||||||
|
|
||||||
|
const params = useParams();
|
||||||
|
|
||||||
|
const [channels, setChannels] = useState([]);
|
||||||
|
|
||||||
|
const updateChannels = () => {
|
||||||
|
jsonRequest("/channels/" + params.id)
|
||||||
|
.then((c) => setChannels(c))
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
updateChannels();
|
||||||
|
|
||||||
|
const interval = setInterval(() => updateChannels(), 30000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChannelContext.Provider value={{channels, updateChannels}}>
|
||||||
|
{children}
|
||||||
|
</ChannelContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user