Skip to content

Instantly share code, notes, and snippets.

View fredrikbergqvist's full-sized avatar

Fredrik Bergqvist fredrikbergqvist

View GitHub Profile
@fredrikbergqvist
fredrikbergqvist / types1.tsx
Last active November 11, 2019 19:36
Examples of TypeScript with React, Redux and Material UI
import * as React from "react";
interface OwnProps {
myProp:string;
}
const MyButton: React.FC<OwnProps> = (props) => {
return (<button />);
}
@fredrikbergqvist
fredrikbergqvist / sitemap.xml.ts
Last active June 9, 2020 07:34
A sitemap example for next.js
import { NextPageContext } from "next";
const blogPostsXml = (blogPosts: IBlogPostListItem[]) => {
let latestPost = 0;
let postsXml = "";
blogPosts.map(post => {
const postDate = Date.parse(post.createdAt);
if (!latestPost || postDate > latestPost) {
latestPost = postDate;
}
import { useEffect } from "react";
export const useIntersectionObserver = (
callback: (unknown) => unknown,
options = {
root: null,
threshold: 0.1,
rootMargin: "0px",
},
reference: HTMLElement | null = null,
@fredrikbergqvist
fredrikbergqvist / Rss.ts
Created November 29, 2019 15:21
How to create an RSS feed for next.js
import React from "react";
import { NextPageContext } from "next";
const blogPostsRssXml = (blogPosts: IBlogPost[]) => {
let latestPostDate: string = "";
let rssItemsXml = "";
blogPosts.forEach(post => {
const postDate = Date.parse(post.createdAt);
if (!latestPostDate || postDate > Date.parse(latestPostDate)) {
latestPostDate = post.createdAt;