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'; | |
const PrivateRoute = ({ | |
component: Component, | |
isAuthenticated, | |
redirectTo, | |
...rest | |
}) => ( | |
<Route |
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, { Component } from "react"; | |
const WithForm = (FormFields, action) => { | |
return class Form extends Component { | |
handleOnChange = event => { | |
const inputTarget = event.currentTarget || event.srcElement; | |
const { title, value } = inputTarget; | |
this.setState( | |
{ | |
[title]: value |
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 user = { | |
firstName: "John", | |
}; | |
const userProxy = new Proxy(user, {}); | |
console.log(userProxy.firstName); // John | |
userProxy.firstName = "Johnny"; |
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 user = { | |
firstName: "John", | |
}; | |
const getHandler = (obj, prop) => { | |
// get object attributes | |
if(prop in obj) { | |
return obj[prop]; | |
} | |
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 user = { | |
firstName: "John", | |
}; | |
const getHandler = (obj, prop) => { | |
// get object attributes | |
if(prop in obj) { | |
return Reflect.get(obj, prop); // Use object's static method | |
} | |
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
/* UTILS */ | |
const getFullName = (firstName, lastName, middleName) => | |
[firstName, middleName, lastName].filter((n) => !!n).join(" "); | |
const getFormattedBalance = (locale, currency, value) => { | |
return new Intl.NumberFormat(locale, { | |
style: "currency", | |
currency | |
}).format(value); |
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
/* UTILS */ | |
const getFullName = (firstName, lastName, middleName) => | |
[firstName, middleName, lastName].filter((n) => !!n).join(" "); | |
const getFormattedBalance = (locale, currency, value) => { | |
return new Intl.NumberFormat(locale, { | |
style: "currency", | |
currency | |
}).format(value); | |
}; |
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
/* PROXY */ | |
const handleSet = (obj, prop, value) => { | |
if (prop === "content" && value.length > 0 && value.length < 255) { | |
const { content, lastUpdated, history = [] } = obj; | |
const historyUpdated = [...history, { content, lastUpdated }]; | |
if (content && lastUpdated) { | |
Reflect.set(obj, "history", historyUpdated); | |
} |
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
/* PROXY */ | |
const handleGet = (obj, prop) => { | |
if (prop === "undo") { | |
const last = obj.history.pop(); | |
if (!last) { | |
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
interface User { | |
firstName: string; | |
middleName?: string; | |
lastName: string; | |
email: string; | |
balance: number; | |
currency: string; | |
locale: string; | |
} |
OlderNewer