Skip to content

Instantly share code, notes, and snippets.

View fedek6's full-sized avatar
🎯
Focusing

Konrad Fedorczyk fedek6

🎯
Focusing
View GitHub Profile
@fedek6
fedek6 / flaten.ts
Created September 14, 2021 12:50
Flatten object literal with other objects (without knowing property names)
const typography = {
primary: {
family: "Lato"
},
secondary: {
family: "Roboto"
}
};
const aliases = Object.entries(typography)
@fedek6
fedek6 / index.ts
Created August 20, 2021 10:06
Enforce object` integrity in TypeScript
export type PrimarySet = Record<keyof typeof primary, string>;
export const primary = {
primary200: "--primary-200",
primary300: "--primary-300",
primary400: "--primary-400",
primary500: "--primary-500",
}
export const primaryShades: PrimarySet = {
@fedek6
fedek6 / preview.js
Created August 17, 2021 09:28
Remove canvas from Storybook preview
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
previewTabs: {
canvas: {
@fedek6
fedek6 / Readme.md
Created August 15, 2021 18:15
Working Linaria config for Storybook (Webpack 5)

You must use Storybook with webpack5!

npx sb@next init --builder webpack5

Remember to install all nedded packages because debugging babel deps might be tricky.

Enjoy!

@fedek6
fedek6 / loader.js
Created August 12, 2021 13:04
Custom loader for Webpack (in Next.js)
module.exports = function (source) {
console.log("The original file was here:", this.resourcePath);
console.log(source);
return source;
};
@fedek6
fedek6 / useLocalStorage.ts
Created August 2, 2021 20:32
Working useLocalStorage hook for Next.js (no warnings in console)
/* eslint-disable no-console */
/* eslint-disable react-hooks/exhaustive-deps */
import { useState, useEffect } from "react";
export const useLocalStorage = <T>(key: string, initialValue: T) => {
const [storedValue, setStoredValue] = useState<T | undefined>();
const setValue = (value: T) => {
window.localStorage.setItem(key, JSON.stringify(value));
};
@fedek6
fedek6 / browser-sync.sh
Created July 19, 2021 12:08
Browser sync example for simple and quick proxy to local project
browser-sync start --proxy "localhost:3000" --no-ui --port 3001
@fedek6
fedek6 / index.ts
Created June 24, 2021 13:27
Working TypeScript debug example for Visual Studio Code
// src/index.ts
import { lubiePlacki } from "./placki";
function printMessage(msg: string): void {
console.log(`Message: ${msg}`);
}
printMessage("Hello, TypeScript");
debugger;
lubiePlacki();
@fedek6
fedek6 / tsconfig.json
Created June 24, 2021 08:26
Working tsconfig for Node 15
{
"compilerOptions": {
"target": "es2018",
"outDir": "./dist",
"rootDir": "./src",
"noEmitOnError": true,
"module": "commonjs"
}
}
@fedek6
fedek6 / .eslintrc.js
Created June 16, 2021 12:30
How to create react app with Typescript, ESlint, Prettier and Airbnb config (using yarn).
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
"plugin:react/recommended",
"airbnb",
"plugin:import/typescript",
"prettier",