Skip to content

Instantly share code, notes, and snippets.

View cjkihl's full-sized avatar

Carl-Johan Kihl cjkihl

View GitHub Profile
@cjkihl
cjkihl / settings.json
Created December 9, 2024 04:33
TailwindCSS Config for Autocomplete
{
// Config for VsCode Tailwind CSS IntelliSense extension for React
// Type hints for className and class attributes
"tailwindCSS.classAttributes": [
"class",
"className",
],
// Type hints for variables and properties ending with *className
"tailwindCSS.experimental.classRegex": [
@cjkihl
cjkihl / NextJS GTM _app.tsx
Last active October 17, 2022 04:05
NextJS GTM _app.tsx
import "../styles/globals.css";
import type { AppProps } from "next/app";
import useEvents from "../gtm/useEvents";
import Tag from "../gtm/Tag";
function MyApp({ Component, pageProps }: AppProps) {
useEvents();
return (
<>
<Tag />
@cjkihl
cjkihl / NextJS GTM dataLayer.d.ts
Last active October 17, 2022 04:07
NextJS GTM dataLayer.d.ts
export declare global {
interface Window {
dataLayer?: DataLayer.EventParameters[];
}
}
declare namespace DataLayer {
interface EventParameters {
[key: string]: any;
}
@cjkihl
cjkihl / NextJS GTM useEvents.ts
Last active October 17, 2022 04:06
NextJS GTM useEvents.ts
import { useRouter } from "next/router";
import { useEffect } from "react";
const useEvents = () => {
const router = useRouter();
useEffect(() => {
const onRouteChangeComplete = (url: string) => {
window.dataLayer?.push({
event: "route_complete",
url,
@cjkihl
cjkihl / NextJS GTM Tag.tsx
Last active October 30, 2022 04:17
NextJS GTM Tag.tsx
import Script from "next/script";
import { FC } from "react";
// Your Google Tag Manager Container ID
const GTM_ID = "GTM-XXXXXXX";
const Tag: FC = () => {
return (
<>
<Script id="GTMDataLayer" strategy="afterInteractive">
{
"React TypeScript Component": {
"prefix": ["comp"],
"body": "import { FC } from 'react'\n\ninterface Props {}\n\nconst ${1:Name}: FC<Props> = (props) => {\nreturn <div>$0</div>\n}\n\nexport default ${1:Name}"
}
}
@cjkihl
cjkihl / InstallContainers.bat
Created April 5, 2020 08:53
Install Docker on Windows 10 Home
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*containers*.mum >containers.txt
for /f %%i in ('findstr /i . containers.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del containers.txt
dism /online /enable-feature /featurename:Containers -All /LimitAccess /ALL
pause
/**
* For full implementation with tests etc, see https://github.com/caki0915/arrayFlatten
*
* @param {Array} array The array to flatten.
* @param {number} depth The recursion depth.
* @param {Array} result Used for recursion.
* @returns {Array} Returns the new flattened array.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const arrayFlatten = (array: Array<any> = null, depth = 10, result: Array<any> = []): Array<any> => {
// Component with renderProps that will add mouse position to the compoent that uses it.
class Mouse extends React.Component {
constructor(props) {
super(props);
this.state = { mouseX: 0, mouseY: 0 };
}
onMouseMove = e => {
this.setState({ mouseX: e.clientX, mouseY: e.clientY });
};
componentDidMount() {
@cjkihl
cjkihl / RenderPropsExample.js
Created April 29, 2018 07:01
React RenderProps Example
// Component with renderProps that will add mouse position to the compoent that uses it.
class Mouse extends React.Component {
constructor(props) {
super(props);
this.state = { mouseX: 0, mouseY: 0 };
}
onMouseMove = e => {
this.setState({ mouseX: e.clientX, mouseY: e.clientY });
};
componentDidMount() {