Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kykean
kykean / WithRecaptcha.js
Created July 30, 2018 09:12
Recaptcha script on demand loading with react
import { compose,
lifecycle,
withHandlers,
withState,
withStateHandlers,
} from 'recompose';
import { scriptExists } from '../Helper';
import { withSpinnerWhileLoading } from '../Spinner';
export const scriptSrc = 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit';
@kykean
kykean / MainPage.js
Created July 25, 2017 15:27
React - Function as a child component to share state between siblings
import React, { Component } from 'react';
import propTypes from 'PropTypes';
import StateWrapper from './StateWrapper';
import CompA from 'CompA';
import CompB from 'CompB';
import CompC from 'CompC';
class MainPage extends Component {
render() {
//layout are determined by children
@kykean
kykean / react-i18next.js
Created June 9, 2017 09:19
jest manual mock to replace react-i18next, so tests can use mount with stubs covering lifecycle methods.
// place in __mocks__/react-i18next.js , same directory level with node_modules
const i18next = jest.genMockFromModule('react-i18next');
i18next.t = (i) => i;
i18next.translate = (c) => (k) => k;
module.exports = i18next;