Skip to content

Commit 18a9430

Browse files
authored
single-page-app: Separate context from app (#422)
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent aa85330 commit 18a9430

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

single-page-app/ui/src/App.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import {ChakraProvider, extendTheme} from '@chakra-ui/react'
2-
import {createContext, useReducer} from 'react'
2+
import {useReducer} from 'react'
33
import {BrowserRouter as Router, Route, Routes} from "react-router-dom"
44

55
import Auth from "./components/Auth"
66
import Home from "./components/Home"
77
import Login from "./components/Login"
88
import Logout from "./components/Logout"
9-
import {TAuthContext, TDataContext} from "./@types/app"
9+
import {AuthContext, DataContext} from "./context"
1010
import {dataInitialState, dataReducer, userInitialState, userReducer} from "./store/reducer"
1111

12-
export const AuthContext = createContext<TAuthContext | null>(null)
13-
export const DataContext = createContext<TDataContext | null>(null)
14-
1512
const theme = extendTheme({
1613
colors: {
1714
primary: {

single-page-app/ui/src/components/Auth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useEffect, useContext} from "react"
22
import {Navigate} from "react-router-dom"
3-
import {AuthContext} from "../App"
3+
import {AuthContext} from "../context"
44
import {TAuthContext} from "../@types/app"
55
import Home from "./Home"
66

single-page-app/ui/src/components/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@chakra-ui/react'
99
import {useContext} from "react"
1010

11-
import {AuthContext} from "../App"
11+
import {AuthContext} from "../context"
1212
import {
1313
IHomeProps,
1414
TAuthContext} from "../@types/app"

single-page-app/ui/src/components/Login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useToast} from '@chakra-ui/react'
22
import {useEffect, useContext} from "react"
33
import {Navigate} from "react-router-dom"
4-
import {AuthContext} from "../App"
4+
import {AuthContext} from "../context"
55
import {TAuthContext} from "../@types/app"
66
import Home from "./Home"
77

single-page-app/ui/src/components/User.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
useDisclosure,
2828
useToast,
2929
} from '@chakra-ui/react'
30-
import {AuthContext} from "../App"
30+
import {AuthContext} from "../context"
3131
import {IUser, TAuthContext} from "../@types/app"
3232
import {AuthProviders} from "../providers.tsx"
3333

single-page-app/ui/src/context.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {createContext} from 'react'
2+
import {TAuthContext, TDataContext} from "./@types/app"
3+
4+
export const AuthContext = createContext<TAuthContext | null>(null)
5+
export const DataContext = createContext<TDataContext | null>(null)

single-page-app/ui/src/hoc.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useContext} from "react"
22

3-
import {AuthContext, DataContext} from "./App"
3+
import {AuthContext, DataContext} from "./context"
44
import {
55
IComponentWithDataProp,
66
IComponentWithUserProp,

0 commit comments

Comments
 (0)