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"; | |
export const Modal = (props: React.ComponentProps<"dialog">) => { | |
const ref = useRef(); | |
useEffect(() => { | |
const dialog = ref.current; | |
dialog.showModal(); | |
return () => dialog.close(); | |
}, []); |
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 { deepCopy } from "./deep-copy"; | |
import { gsid } from "./idgen"; | |
/** | |
* Determines the _new state_, given `TAction`. | |
* | |
* ```ts | |
* const reducer = (state, action) => { | |
* if (action.type === "increment") return state + 1; |
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, useRef, useEffect } from "react"; | |
import { transform } from "@babel/standalone"; | |
import { TransformOptions } from "@babel/core"; | |
import { useDebounce } from "use-debounce"; | |
import { v4 } from "uuid"; | |
type UseCodePreviewArgs = { | |
js: string | undefined; | |
html: string | undefined; | |
css: string | undefined; |
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, { useEffect, useState } from "react" | |
export function usePagination( | |
list = [{}], | |
options = { perPage: 10, onPageChange: () => {} } | |
) { | |
const [activePage, setActivePage] = useState(1) | |
const [pages, setPages] = useState([1]) | |
const [filteredList, setFilteredList] = useState([{}]) | |
const { perPage, onPageChange } = options; |
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 } from "react"; | |
const getTotalOffset = (el: HTMLElement) => { | |
let a: any = el, | |
x = 0, | |
y = 0; | |
while (a) { | |
x += a.offsetLeft; | |
y += a.offsetTop; | |
a = a.offsetParent; |
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 { useState, useEffect } from "react"; | |
import axios from "axios"; | |
const useAxios = (url, dependencies) => { | |
const [isLoading, setLoading] = useState(true); | |
const [data, setData] = useState({}); | |
useEffect(() => { | |
setData({}); | |
const getData = async () => { | |
axios | |
.get(url) |
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"; | |
export default class WrapperWithBeforeunload extends React.Component{ | |
componentDidMount(){ | |
// Add event listener on component mount | |
window.addEventListener("beforeunload", this.beforeUnloadHandler); | |
} | |
componentWillUnmount(){ | |
// Remove event listener on component unmount | |
window.removeEventListener("beforeunload", this.beforeUnloadHandler); | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="main.css" /> | |
<title>dev-name</title> <!-- title/name --> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>dev-name</h1> <!-- title/name --> |