This file contains hidden or 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
| var Promise = function(wrappedFn, wrappedThis) { | |
| this.then = function(wrappedFn, wrappedThis) { | |
| this.next = new Promise(wrappedFn, wrappedThis); | |
| return this.next; | |
| }; | |
| this.run = function() { | |
| wrappedFn.promise = this; | |
| wrappedFn.apply(wrappedThis); | |
| }; |
This file contains hidden or 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
| /** | |
| * useScroll React custom hook | |
| * Usage: | |
| * const { scrollX, scrollY, scrollDirection } = useScroll(); | |
| */ | |
| import { useState, useEffect } from "react"; | |
| export function useScroll() { | |
| const [lastScrollTop, setLastScrollTop] = useState(0); |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>Add React in One Minute</title> | |
| </head> | |
| <body> | |
| <h2>Add React in One Minute</h2> | |
| <p>This page demonstrates using React with no build tooling.</p> |
This file contains hidden or 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
| // BrowserRouter is the router implementation for HTML5 browsers (vs Native). | |
| // Link is your replacement for anchor tags. | |
| // Route is the conditionally shown component based on matching a path to a URL. | |
| // Switch returns only the first matching route rather than all matching routes. | |
| import { | |
| BrowserRouter as Router, | |
| Link, | |
| Route, | |
| Switch, | |
| } from 'react-router-dom'; |
This file contains hidden or 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
| // encode(decode) html text into html entity | |
| var decodeHtmlEntity = function(str) { | |
| return str.replace(/&#(\d+);/g, function(match, dec) { | |
| return String.fromCharCode(dec); | |
| }); | |
| }; | |
| var encodeHtmlEntity = function(str) { | |
| var buf = []; | |
| for (var i=str.length-1;i>=0;i--) { |
This file contains hidden or 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
| @mixin for-phone-only { | |
| @media (max-width: 599px) { @content; } | |
| } | |
| @mixin for-tablet-portrait-up { | |
| @media (min-width: 600px) { @content; } | |
| } | |
| @mixin for-tablet-landscape-up { | |
| @media (min-width: 900px) { @content; } | |
| } | |
| @mixin for-desktop-up { |
This file contains hidden or 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
| // connect() is a function that injects Redux-related props into your component. | |
| // You can inject data and callbacks that change that data by dispatching actions. | |
| function connect(mapStateToProps, mapDispatchToProps) { | |
| // It lets us inject component as the last step so people can use it as a decorator. | |
| // Generally you don't need to worry about it. | |
| return function (WrappedComponent) { | |
| // It returns a component | |
| return class extends React.Component { | |
| render() { | |
| return ( |