Skip to content

Instantly share code, notes, and snippets.

View DennyScott's full-sized avatar

Denny Scott DennyScott

  • Winnipeg, Manitoba
View GitHub Profile
npm install - save-dev @babel/core @babel/cli @babel/plugin-proposal-optional-chaining
const personOne = {
firstName: "Denny",
lastName: "Scott",
contact: {
phoneNumber: 555–555–5555,
twitter: "@gitinbit"
}
}
function getUserForPhoneDirectory(person) {
npx babel - plugins @babel/plugin-proposal-optional-chaining index.js
function getUserForPhoneDirectory(person) {
var _person$contact;
const firstName = person === null || person === void 0 ? void 0 : person.firstName;
const lastName = person === null || person === void 0 ? void 0 : person.lastName;
const phoneNumber = person === null || person === void 0 ? void 0 : (_person$contact = person.contact) === null || _person$contact === void 0 ? void 0 : _person$contact.phoneNumber;
if (firstName && lastName && phoneNumber) {
return `${firstName} ${lastName} - ${phoneNumber}`;
}
}
{
"plugins": [
"@babel/plugin-proposal-optional-chaining"
]
}
import styled from 'styled-components';
const Card = styled.div`
box-sizing: border-box;
max-width: 410px;
margin: 0 auto;
padding: 0 2rem;
display: flex;
flex-direction: column;
align-items: center;
import React, { useState } from "react"
...
function App(props) {
const existingTokens = JSON.parse(localStorage.getItem("tokens"));
const [authTokens, setAuthTokens] = useState(existingTokens);
const setTokens = (data) => {
localStorage.setItem("tokens", JSON.stringify(data));
setAuthTokens(data);
}
'no-restricted-syntax': [
'error',
{
selector: "CallExpression[callee.name='require']",
message: 'Require is no longer allowed, please use an import statement'
}
]
import React, { useState } from 'react';
function Header(props) {
const [title, setTitle] = useState('Title');
}
import React, { useState } from “react”;
export default function App() {
const [counter, setCounter] = useState(1);
const onClick = () => {
setCounter(counter + 1);
console.log(counter);
};