Skip to content

Instantly share code, notes, and snippets.

View florianmartens's full-sized avatar
🏠
Working from home

florianmartens

🏠
Working from home
View GitHub Profile
interface SmallerType {
foo: string;
baz: string;
}
let obj: SmallerType;
const smaller = {
// included in our requirements
foo: "foo",
baz: "bar",
// infinite number of other properties
interface BigType {}
const zap: BigType = {
foo: "foo",
bar: "bar",
// -> You can add a million properties to this
// -> And it would still be of type BigType
}
{
"presets": ["next/babel"],
"plugins": [
[
"formatjs",
{
"idInterpolationPattern": "[sha512:contenthash:base64:6]",
"ast": true
}
]
{
...
"scripts": {
"dev": "next dev",
"build": "npm run i18n && next build",
"start": "next start",
"extract:i18n": "formatjs extract '{pages,components,sections}/**/*.{js,ts,tsx}' --format simple --id-interpolation-pattern '[sha512:contenthash:base64:6]' --out-file content/locales/en.json",
"compile:i18n": "formatjs compile-folder --ast --format simple content/locales content/compiled-locales",
"i18n": "npm run extract:i18n && npm run compile:i18n"
},
import English from "../compiled-locales/en.json";
import German from "../compiled-locales/de.json";
function MyApp({ Component, pageProps }: AppProps) {
const { locale } = useRouter();
const [shortLocale] = locale ? locale.split("-") : ["en"];
const messages = useMemo(() => {
switch (shortLocale) {
case "de":
import { useEffect, useReducer } from "react";
const reducer = (state, action) => {
switch(action.type) {
case "Increment":
return state + 1;
default:
return state;
}
}
import { useState, useEffect } from "react";
export default function App() {
const initalState = 0;
const [count, setCount] = useState(initalState);
useEffect(() => {
const interval = setInterval(() => {
setCount(count + 1);
}, 1000);
import "./styles.css";
import { useState, useEffect } from "react";
export default function App() {
const initalState = 0;
const [count, setCount] = useState(initalState);
useEffect(() => {
setInterval(() => {
setCount(old => old + 1);
import { useState, useEffect, useRef } from "react";
export default function App() {
const initalState = 0;
const [count, setCount] = useState(initalState);
const counterRef = useRef(initalState);
useEffect(() => {
counterRef.current = count;
})
# Resetting the database without deleting it
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
# Deleting all entries from a table
DELETE FROM table_name;