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
////////////// HTML ////////////// | |
<!-- item will be appened to this layout --> | |
<div id="log" class="sl__chat__layout"> | |
</div> | |
<!-- chat item --> | |
<script type="text/template" id="chatlist_item"> | |
<div data-from="{from}" data-id="{messageId}"> | |
<span class="meta" style="color: {color}"> |
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
// This is the main layout of the whole website for selling some products | |
export default function PrimaryLayout() { | |
return ( | |
<> | |
<Header /> | |
<main> | |
<Switch> | |
<Route path="/" exact> | |
<Home /> | |
</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
export default function usePromise(api) { | |
const [state, dispatch] = useReducer( | |
(state, action) => { | |
switch (action.type) { | |
case 'LOADING': | |
return { ...state, loading: true } | |
case 'RESOLVED': | |
return { ...state, loading: false, response: action.response, error: null } | |
case 'ERROR': | |
return { ...state, loading: false, response: null, error: action.error } |
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, { useState, useEffect, useReducer, useMemo } from 'react' | |
import ReactDOM from 'react-dom' | |
// let text = 'hellllooooo' | |
// I AM REACT | |
// let domTable = {} | |
// let element = Counter // state = 0 | |
// commit(element, domTable) |
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 { useEffect } from "react"; | |
import { useAppReducer } from "../AppContext"; | |
export default function useLocal() { | |
const dispatch = useAppReducer(); | |
useEffect(() => { | |
dispatch({ | |
type: "GET_FROM_LOCAL_STATE", | |
somePieceOfState: localStorage.getItem("some_state") || "defaultvalue", |
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
export const SomeButton = forwardRef( | |
( | |
{ children, onSelect, ...props }, | |
forwardedRef | |
) => { | |
return ( | |
<button | |
{...props} | |
onClick={onSelect} | |
ref={forwardedRef} |
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
function useMedia(query) { | |
const [matches, setMatches] = useState(window.matchMedia(query).matches) | |
useEffect(() => { | |
const media = window.matchMedia(query) | |
if (media.matches !== matches) { | |
setMatches(media.matches) | |
} | |
const listener = () => { | |
setMatches(media.matches) |
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 cities = [ | |
{ | |
city: "Abbeville", | |
state: "Louisiana", | |
}, | |
{ | |
city: "Aberdeen", | |
state: "Maryland", | |
}, | |
{ |
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 time | |
print "..." | |
time.sleep(1) | |
print "..." | |
print "..." | |
print "..." | |
print "..." | |
time.sleep(1) | |
print "..." |
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
// Modified version of this Stack Overflow response: | |
// https://stackoverflow.com/a/48459005/1950503 | |
// (Removes ramda dependency, adds .trim() to string replacer, adds it to Jest global var instead of exporting) | |
// To use: | |
// Put `<rootDir>/path/to/customWhitespaceMatcher.js` in your Jest config under setupFiles | |
// Call it in your tests like this: | |
// expect( | |
// customMatchers.whitespaceMatcher(receivedResult, expectedResult).pass | |
// ).toBeTruthy(); |