movie-web/src2/hooks/useMovie.js

31 lines
894 B
JavaScript
Raw Normal View History

2021-07-14 00:31:37 +02:00
import React from 'react'
const MovieContext = React.createContext(null)
export function MovieProvider(props) {
const [page, setPage] = React.useState("search");
const [stream, setStream] = React.useState("");
2021-08-02 14:15:18 +02:00
const [streamData, setStreamData] = React.useState(null); //{ title: "", slug: "", type: "", episodes: [], seasons: [] })
2021-07-14 00:31:37 +02:00
return (
<MovieContext.Provider value={{
navigate(str) {
setPage(str)
},
page,
setStreamUrl: setStream,
streamUrl: stream,
streamData,
setStreamData(d) {
setStreamData(p => ({...p,...d}))
},
2021-08-02 14:15:18 +02:00
resetStreamData() { setStreamData(null) }
2021-07-14 00:31:37 +02:00
}}>
{props.children}
</MovieContext.Provider>
)
}
export function useMovie(props) {
return React.useContext(MovieContext);
}