Skip to content

Instantly share code, notes, and snippets.

View lukebrandonfarrell's full-sized avatar
✌️
fixing bugs since 1996

Luke Brandon Farrell lukebrandonfarrell

✌️
fixing bugs since 1996
View GitHub Profile
@lukebrandonfarrell
lukebrandonfarrell / useEffectAfterMount.js
Last active June 12, 2020 14:43
Use an effect after the component has been mounted.
/**
* Use effect after component mount
*
* @param effect
* @param deps
*
* @return {*}
*/
export function useEffectAfterMount(effect, deps) {
const isFirstRun = useRef(true);
@lukebrandonfarrell
lukebrandonfarrell / react-native.config.js
Last active April 10, 2020 14:38
React Native Config 0.60+
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./path-to-assets'], // stays the same
};
/**
* @author Luke Brandon Farrell
* @description
*/
/* NPM - Node Package Manage */
import React, { useState } from "react";
import PropTypes from "prop-types";
const AsyncBoundary = ({
useEffect(() => {
if((isReferralsError && !isReferralsEmpty) || (isUserError && !isUserEmpty)){
actionTipRef.current.show("Unable to load latest results")
}
}, [isReferralsError, isUserError, isReferralsEmpty, isUserEmpty])
const { data: userData, isLoading: isUserLoading, error: isUserError } = ...;
const { data: referralData, isLoading: isReferralsLoading, error: isReferralsError } = ...;
const isUserReferralEmpty = _isNil(referralUrl);
const isReferralsEmpty = _isEmpty(referrals);
const isReferralsAvailable = !_isEmpty(referrals) && !isReferralsError;
#import "DarkMode.h"
#import <React/RCTLog.h>
@implementation DarkMode
RCT_EXPORT_MODULE();
@end
#import <React/RCTBridgeModule.h>
@interface DarkMode : NSObject <RCTBridgeModule>
@end
@lukebrandonfarrell
lukebrandonfarrell / example.js
Created October 3, 2019 13:50
Sets an array of errors for a formik form
/*
* The first arguement is an object of errors e.g. { email: "Email has been taken" }
* The seound arguement is a refrence to your formik form (e.g. useRef)
* The third arguement is an optional mapping
*/
useSetFormikErrors(errors, formikRef, { dob: "birthday" });
const counterValue = 0;
const initialCounterValue = useInitialValue(selectedBrands);
const hasCounterChanged = counterValue !== initialCounterValue;
@lukebrandonfarrell
lukebrandonfarrell / funnels.ts
Created August 13, 2019 08:14
Funnels TypeScript implementation for RMN
/**
* @author Luke Brandon Farrell
* @description Funnels allow us to re-use screens with react-native-navigation
* and build more complex patterns. In the context of this utility a stack
* refers to a single screen, where as a funnel refres to a collection of screens.
*/
import { Platform } from "react-native";
import { Navigation, Layout, Options } from "react-native-navigation";
import * as NavigationLayouts from "react-native-navigation-layouts";