This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { configureStore } from '@reduxjs/toolkit' | |
import userReducer from './reducers/userReducer' | |
import orderReducer from './reducers/orderReducer' | |
const store = configureStore({ | |
reducer: { | |
users: userReducer, | |
orders: orderReducer | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combineReducers } from 'redux' | |
import userReducer from './reducers/userReducer' | |
import orderReducer from './reducers/orderReducer' | |
const rootReducer = combineReducers({ | |
users: userReducer, | |
orders: orderReducer | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import react from "../node_modules/eslint-config-airbnb-base/rules/strict.js"; | |
function isError(config) { | |
if(Array.isArray(config)) { | |
if(config[0] === 2 || config[0] === "error") { | |
return config; | |
} | |
} | |
if (config === 2 || config === "error") | |
return config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { Route, Redirect } from "react-router-dom"; | |
import { useAuthContext } from "../contexts/AuthContext"; | |
export default function PrivateRoute({ children, ...rest }) { | |
const { auth } = useAuthContext(); | |
return ( | |
<Route | |
{...rest} | |
render={({ location }) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import { | |
useAuthContext, | |
loginSuccess, | |
loginFail | |
} from "../contexts/AuthContext"; | |
import { apiLogin } from "../api/auth"; | |
import { Redirect } from "react-router-dom"; | |
export default function Login() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Todos from "./components/Todos"; | |
import Login from "./components/Login"; | |
import { TodoProvider } from "./contexts/TodoContext"; | |
import { AuthProvider, useAuthContext, logout } from "./contexts/AuthContext"; | |
import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | |
import "./App.css"; | |
function App() { | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, useReducer, useContext } from "react"; | |
export const AuthContext = createContext(); | |
// Initial state | |
const initialState = { | |
isLoggedIn: false, | |
name: null, | |
error: null | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
// A fake authenticator to mock async api call | |
export async function apiLogin(name) { | |
await delay(2000); | |
if (name === "John") return true; | |
throw new Error("User not found!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Todos from "./components/Todos"; | |
import Login from "./components/Login"; | |
import { TodoProvider } from "./contexts/TodoContext"; | |
import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | |
import "./App.css"; | |
function App() { | |
return ( | |
<Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
export default function Login() { | |
const [name, setName] = useState(""); | |
const [loading, setLoading] = useState(false); | |
function handleLogin() { | |
// Handle login here | |
} |
NewerOlder