Skip to content

Instantly share code, notes, and snippets.

View bietkul's full-sized avatar

Kuldeep Saxena bietkul

View GitHub Profile
@bietkul
bietkul / Image.js
Created February 14, 2019 17:58
A component to use progressive images.
import React from 'react';
import PropTypes from 'prop-types';
import ProgressiveImage from 'react-progressive-image';
const Image = ({
src, alt, placeholderStyle, ...props
}) => (
<ProgressiveImage src={src} placeholder="">
{(currentSrc, loading) => (loading ? (
<div style={{ background: '#040203', ...placeholderStyle }} {...props} />
@bietkul
bietkul / OfflineSupport.js
Created February 14, 2019 19:03
A component to register a service worker
import React from 'react';
class OfflineSupport extends React.PureComponent {
componentDidMount() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js')
.then(() => console.log('service worker registered.'))
.catch(err => console.dir(err));
}
}
import React from 'react';
import App, { Container } from 'next/app';
import OfflineSupport from '../components/OfflineSupport';
class CustomApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<Container>
<OfflineSupport />
<Component {...pageProps} />
@bietkul
bietkul / next.config.js
Last active January 15, 2022 13:08
Custom Next.js Config
if (typeof require !== 'undefined') {
require.extensions['.css'] = () => null;
}
const NextWorkboxPlugin = require('next-workbox-webpack-plugin');
const withCSS = require('@zeit/next-css');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const path = require('path');
module.exports = withCSS({
webpack(config, { isServer, buildId, dev }) {
config.node = {
const express = require('express');
const next = require('next');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const Cache = require('lru-cache');
const ssrCache = new Cache({
max: 20, // not more than 20 results will be cached
@bietkul
bietkul / Mixpanel.Container.js
Created February 14, 2019 22:08
Container with Mixpanel
import Head from 'next/head';
import React from 'react';
import { css } from '@emotion/core';
import {
node, string, oneOfType, object
} from 'prop-types';
import { ReactiveBase } from '@appbaseio/reactivesearch';
import mixpanel from 'mixpanel-browser';
import { MixpanelProvider } from 'react-mixpanel';
import { Layout } from 'antd';
import React from 'react';
import { connect } from 'react-redux';
import { Button } from 'antd';
import {
object, func, string, oneOfType, number, array,
} from 'prop-types';
import {
Content, Footer, Header, Container,
} from '../components/Layout';
import Page from '../components/Page';
import some from 'lodash/some';
import AppConstants from '../utils/constants';
const initialProductState = {
items: [],
totalPrice: 0,
};
const addItems = (items = [], payload) => {
const newItems = items.map(item => item);
@bietkul
bietkul / PurchaseButton.js
Created February 15, 2019 02:08
Purchase button component
import React from 'react';
import PropTypes from 'prop-types';
import StripeCheckout from 'react-stripe-checkout';
const onToken = (token) => {
console.log('Stripe Token', token);
};
const Purchase = ({
price, title, children, ...props
@bietkul
bietkul / cart.js
Last active February 15, 2019 02:23
Cart Page to list down the cart items
import React from 'react';
import { Card, Button } from 'antd';
import { connect } from 'react-redux';
import get from 'lodash/get';
import { array, number, func } from 'prop-types';
import {
Content, Footer, Header, Container,
} from '../components/Layout';
import Page from '../components/Page';
import { removeToCart } from '../modules/actions';