From cf043dab4cfc8c3e7f4afcf6c60911e0bdb89fc8 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Sat, 19 Mar 2022 00:10:13 +0600 Subject: [PATCH] Add contexts --- src/contexts/LoadingContext.js | 15 +++++++++++++++ src/contexts/ThemeContext.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/contexts/LoadingContext.js create mode 100644 src/contexts/ThemeContext.js diff --git a/src/contexts/LoadingContext.js b/src/contexts/LoadingContext.js new file mode 100644 index 0000000..b33cc02 --- /dev/null +++ b/src/contexts/LoadingContext.js @@ -0,0 +1,15 @@ +import { createContext, useState } from 'react'; + +const initialValue = true; + +export const LoadingContext = createContext(); + +export const LoadingProvider = (props) => { + const [loading, setLoading] = useState(initialValue); + + return ( + + {props.children} + + ); +}; diff --git a/src/contexts/ThemeContext.js b/src/contexts/ThemeContext.js new file mode 100644 index 0000000..fb82452 --- /dev/null +++ b/src/contexts/ThemeContext.js @@ -0,0 +1,16 @@ +import { createContext, useState } from 'react'; +import { getInitialTheme } from '../helpers/utils'; + +const initialValue = getInitialTheme(); + +export const ThemeContext = createContext(); + +export const ThemeProvider = (props) => { + const [theme, setTheme] = useState(initialValue); + + return ( + + {props.children} + + ); +};