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
class App extends Component { | |
constructor(props){ | |
super(props) | |
this.scrollToIdOnClick = this.scrollToIdOnClick.bind() | |
} | |
scrollToIdOnClick(event){ | |
event.preventDefault() | |
const element = event.target; |
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 jwt from 'jsonwebtoken'; | |
const authMiddleware = async (ctx, next) => { | |
const { authorization } = ctx.request.headers; | |
if (authorization) { | |
jwt.verify(authorization, 'batman', (err, decoded) => { | |
if (err) return ctx.body = 401 | |
ctx.state.user = decoded.id; | |
console.log(ctx.state.user) |
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 Home from './screens/Home' | |
import PrivateRouter from './components/privateRouter' | |
import Login from './screens/Login' | |
import {BrowserRouter, Switch, Route} from 'react-router-dom' | |
const Router = () => { | |
return ( | |
<BrowserRouter> | |
<div> |
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
// Login.js | |
import React from 'react' | |
const Login = ({history}) => { | |
const loginIn = () => { | |
localStorage.setItem('token', 'batman') | |
history.push('/home') | |
} | |
return ( | |
<div> |
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
// Home.js | |
import React from 'react' | |
const Home = ({history}) => { | |
const redirectLogin = () => { | |
localStorage.removeItem('token') | |
history.push('/') | |
} | |
return ( | |
<div> |
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
// privateRouter.js | |
import React from 'react'; | |
import { Route, Redirect } from 'react-router-dom'; | |
import {isAuthenticated} from './../auth' | |
const PrivateRouter = ({component: Component, ...rest}) => { | |
return ( | |
<Route {...rest} render={(props) => ( | |
isAuthenticated() ? ( | |
<div> |
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
// auth.js | |
export const isAuthenticated = () => localStorage.getItem('token'); |
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
yarn add @babel/cli @babel/core @babel/preset-react @babel/preset-env react react-dom react-hot-loader @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread @babel/plugin-transform-runtime babel-loader css-loader file-loader html-webpack-plugin style-loader url-loader webpack webpack-cli webpack-dev-server |
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 {createAppContainer, createStackNavigator} from 'react-navigation'; | |
import FunctionScreen, {navigationOptions} from './src/screen/Function' | |
import ClassScreen from './src/screen/Class' | |
const Root = createStackNavigator({ | |
ClassScreen: { | |
screen: ClassScreen | |
}, | |
FunctionScreen:{ |
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 { StyleSheet, Text, View } from "react-native"; | |
export default class ClassScreen extends React.Component { | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text>Class component!</Text> | |
</View> |
OlderNewer