Skip to content

Instantly share code, notes, and snippets.

View binhtran04's full-sized avatar

Binh Tran binhtran04

View GitHub Profile
@binhtran04
binhtran04 / CostTable.js
Last active June 5, 2019 06:50
Final CostTable
import React, { useState } from "react";
import "./CostTable.css";
const _defaultCosts = [
{
name: "Rice",
price: 40
},
{
@binhtran04
binhtran04 / CostTableStatic.js
Last active May 31, 2019 10:53
Cost table static
import React, { useState } from "react";
import "./CostTable.css"
const _defaultCosts = [
{
name: "Rice",
price: 40
},
{
@binhtran04
binhtran04 / App.js
Created November 30, 2018 19:07
App component
import React, { Component } from 'react';
import './App.css';
import { BrowserRouter, Switch } from 'react-router-dom';
import Home from './components/Home';
import Dashboard from './components/Dashboard';
import SignIn from './components/SignIn';
import PrivateRoute from './components/PrivateRoute';
import PublicRoute from './components/PublicRoute';
class App extends Component {
@binhtran04
binhtran04 / PublicRoute.js
Created November 30, 2018 19:04
Public route component
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { isLogin } from '../utils';
const PublicRoute = ({component: Component, restricted, ...rest}) => {
return (
// restricted = false meaning public route
// restricted = true meaning restricted route
<Route {...rest} render={props => (
isLogin() && restricted ?
@binhtran04
binhtran04 / PrivateRoute.js
Created November 30, 2018 19:01
Private route component
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { isLogin } from '../utils';
const PrivateRoute = ({component: Component, ...rest}) => {
return (
// Show the component only when the user is logged in
// Otherwise, redirect the user to /signin page
<Route {...rest} render={props => (