Skip to content

Instantly share code, notes, and snippets.

View paigen11's full-sized avatar

Paige Niedringhaus paigen11

View GitHub Profile
@paigen11
paigen11 / og-expression-interpolation.js
Last active September 15, 2019 00:04
The old way of injecting expression values into strings in JavaScript
const c = 10;
const d = 5;
console.log('It used to be harder to calculate that ' + (c + d)
+ '\n is not the same as ' + (2 * c) + ' in a string.');
/* prints: It used to be harder to calculate that 15
is not the same as 20 in a string. */
@paigen11
paigen11 / template-literals-expression-interpolation.js
Created September 15, 2019 00:10
Template literal syntax using expression interpolation
const c = 10;
const d = 5;
console.log(`With the syntactic sugar of ES6 template literals,
doing math in strings like this: ${c + d}
and that: ${2 * c} is a cinch.`);
/* prints: With the syntactic sugar of ES6 template literals,
doing math in strings like this: 15
and that: 20 is a cinch. */
@paigen11
paigen11 / es5-nesting-templates.js
Last active September 15, 2019 00:41
Creating nested template strings in ES5 without template literal assistance.
var classes = 'header';
function isDesktopSize(){
window.innerWidth > 1400 ? true : false;
};
var navbar = {
isOpen: false
};
@paigen11
paigen11 / nested-template-strings.js
Last active September 15, 2019 00:55
Creating a configurable string via ES6 nested template strings
function isDesktopSize(){
window.innerWidth > 1400 ? true : false;
}
var navbar = {
isOpen: true
};
classes = `header ${ isDesktopSize() ? '' :
`icon-${navbar.isOpen ? 'collapse' : 'expand'}` }`;
@paigen11
paigen11 / tagged-template.js
Created September 15, 2019 17:22
Example using tagged templates
var guy = 'Paul';
var age = 96;
function myTag(strings, personExp, ageExp) {
var str0 = strings[0]; // "That "
var str1 = strings[1]; // " is a "
var ageStr;
if (ageExp > 99){
ageStr = 'centenarian';
@paigen11
paigen11 / raw-strings.js
Last active September 15, 2019 18:11
Example of the .raw argument in a string
function tag(strings) {
console.log(strings.raw[0]);
}
tag`I'd like this line 1 \n to ignore the newline and be in line with 1
\n even though I should be on line 3 at this point`;
/* prints: I'd like this line 1 \n to ignore the newline and be in line with 1
\n even though I should be on line 3 at this point */
@paigen11
paigen11 / raw-string-with-expression-interpolation.js
Last active September 15, 2019 18:31
Another raw string example, but with expression interpolation in the template literal too
var str = String.raw`What's up \n${4+7}?`;
console.log(str);
// prints: What's up \n11?
console.log(str.length);
// prints: 15
console.log(str.split('').join(','));
// prints: W,h,a,t,',s, ,u,p, ,\,n,1,1,?
@paigen11
paigen11 / App.js
Created February 1, 2020 23:11
React Socks breakpoint wrapper example
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { BreakpointProvider } from 'react-socks';
import NowPlaying from './containers/NowPlaying/NowPlaying';
import Dashboard from './containers/Dashboard/Dashboard';
import Upcoming from './containers/Upcoming/Upcoming';
import MovieSearch from './containers/MovieSearch/MovieSearch';
import Genres from './containers/Genres/Genres';
import Header from './containers/Header/Header';
import './App.css';
@paigen11
paigen11 / genres-with-breakpoints.js
Created February 1, 2020 23:13
Example of React Socks breakpoints being used inside a JSX component.
return (
<div className="genres-page">
<h1>Choose a Genre</h1>
{(error || loading) && <h3 className="genre-info">{info}</h3>}
<Breakpoint large up>
<div className="genre-list">
{this.renderRedirect()}
{genreInfo}
</div>
</Breakpoint>
@paigen11
paigen11 / genres-with-breakpoints.scss
Created February 1, 2020 23:15
The different CSS which gets rendered based on the React Socks component wrapped in breakpoints.
.genre-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
max-width: 1200px;
grid-gap: 15px;
justify-items: center;
margin: auto;
h3 {
margin: 200px auto;
}