1
0
Fork 0
freesewing/sites/shared/context/loading-context.mjs

25 lines
618 B
JavaScript
Raw Normal View History

import React, { useState } from 'react'
export const LoadingContext = React.createContext(false)
export const LoadingContextProvider = ({ children }) => {
function stopLoading() {
__setLoading({ ...__loading, loading: false })
}
function startLoading() {
__setLoading({ ...__loading, loading: true })
}
function setLoading(loading) {
__setLoading({ ...__loading, loading })
}
const [__loading, __setLoading] = useState({
setLoading,
startLoading,
stopLoading,
loading: false,
})
return <LoadingContext.Provider value={__loading}>{children}</LoadingContext.Provider>
}