View react-loadable-router.js
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 { Switch, Route } from 'react-router-dom' | |
import Loadable from 'react-loadable' | |
const Loading = () => <div>loading...</div> | |
const Home = Loadable({ | |
loader: () => import('./Home'), | |
loading: Loading | |
}) |
View suspense.js
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 MyComponent = () => ( | |
<Suspense fallback={<div>Loading...</div>}> | |
<AsyncComponent /> | |
</Suspense> | |
) | |
View SignIn.jsx
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
function SignIn (props) { | |
const [username, setUsername] = useState('') | |
const [password, setPassword] = useState('') | |
const [pending, setPending] = useState('') | |
const [error, setError] = useState({}) | |
useEffect(()=>{ | |
if(pending) { | |
api.signIn(username, password) | |
.then(res => { |
View useBreakpoints.js
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 { useMemo, createContext, useContext } from 'react' | |
import useMedia from 'Hooks/useMedia' | |
export const BreakpointsContext = createContext() | |
// for provider | |
export function useBreakpoints ({ | |
sm = 480, | |
md = 960, |
View Foo2.jsx
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 useAppReducer from 'Hooks/useAppReducer' | |
export default function Foo () { | |
const [state, dispatch] = useAppReducer() | |
// can read state or dispatch action to appReducer | |
return ( | |
... | |
) | |
} |
View app2.jsx
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 { BrowserRouter } from 'react-router-dom' | |
import Routes from 'Routes' | |
import { useAppReducer, AppReducerContext } from 'Hooks/useAppReducer' | |
export default function App () { | |
const appReducer = useAppReducer() | |
return ( | |
<AppReducerContext.Provider value={appReducer}> | |
<BrowserRouter> |
View useAppReducer.js
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 { createContext, useContext, useReducer } from 'react' | |
import { combineReducers, persistReducer } from 'Reducers/helpers' | |
import TokenReducer from 'Reducers/Token' | |
import FeatureReducer from 'Reducers/Feature' | |
const AppReducer = combineReducers({ | |
token: persistReducer({ key: 'token', storage: localStorage })(TokenReducer), | |
feature: persistReducer({ key: 'feature', storage: sessionStorage })(FeatureReducer) | |
}) |
View Foo.jsx
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 { useContext } from 'react' | |
import { AppReducerContext } from 'app' | |
export default function Foo () { | |
const [state, dispatch] = useContext(AppReducerContext) | |
// can read state or dispatch action to appReducer | |
return ( | |
... | |
) | |
} |
View app.jsx
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 { createContext, useReducer } from 'react' | |
import AppReducer from 'Reducers/AppReducer' | |
import { BrowserRouter } from 'react-router-dom' | |
import Routes from 'Routes' | |
export const AppReducerContext = createContext() | |
const initState = AppReducer() | |
export default function App () { |
View appReducer.js
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, persistReducer } from 'Reducers/helpers' | |
import TokenReducer from 'Reducers/Token' | |
import FeatureReducer from 'Reducers/Feature' | |
const AppReducer = combineReducers({ | |
token: persistReducer({ key: 'token', storage: localStorage })(TokenReducer), | |
feature: persistReducer({ key: 'feature', storage: sessionStorage })(FeatureReducer) | |
}) |
NewerOlder