Skip to content

Instantly share code, notes, and snippets.

View danieljpgo's full-sized avatar
🚀
raising the bar

Daniel Jorge danieljpgo

🚀
raising the bar
View GitHub Profile
@danieljpgo
danieljpgo / remix.ts
Last active September 2, 2022 02:58
/lib/remix.ts
/**
* Create a response with a permanently redirect using `301` as status code.
*/
export function redirectPermanently(
url: string,
init?: Omit<ResponseInit, "status">
) {
return redirect(url, { ...init, status: 301 });
}
@danieljpgo
danieljpgo / _app.tsx
Created August 3, 2022 12:56
Next.js
type NextPageWithLayout = NextPage & {
getLayout?: (page: ReactElement) => ReactNode;
};
type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};
export default function MyApp(props: AppPropsWithLayout) {
const { Component, pageProps } = props;
export type LooseAutocomplete<T extends string> = T | Omit<string, T>;
@danieljpgo
danieljpgo / contributors.md
Created June 8, 2022 13:36
Examples of documentation using .md files
import * as React from 'react';
type ErrorBoundaryState = {
error?: Error;
};
type ErrorBoundaryProps = {
children: React.ReactNode;
fallback: (state: ErrorBoundaryState) => void;
};
import * as React from 'react';
export const useIsomorphicLayoutEffect = typeof window === 'object'
? React.useLayoutEffect
: React.useEffect;
@danieljpgo
danieljpgo / browser.ts
Last active January 28, 2022 22:52
/lib
/**
* Checks if the code is running in the `browser`.
*/
export function isBrowser() {
return typeof window === 'object';
}
/**
* Checks if the code is running in the `server`.
*/
import * as React from 'react';
import PropTypes from 'prop-types';
import { useWindowSize } from '@hooks';
function LeftContainer({ children }) {
const { width } = useWindowSize();
const isDesktop = width > 1023;
return (
<section
import * as React from 'react';
type ErrorBoundaryState = {
error?: Error;
};
type ErrorBoundaryProps = {
children: React.ReactNode;
fallback: React.ReactNode | ((state: ErrorBoundaryState) => void);
};
/**
* Returns the current object from local storage associated with the given key.
* @template T
* @param {String} key The key to set in localStorage for this value
* @returns {T|undefined}
*/
export function getLocalStorageData(key) {
const data = window.localStorage.getItem(key);
try {
return data ? JSON.parse(data) : undefined;