Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / index.js
Created March 6, 2019 06:38
JS: Check if an element is under an anchor element
/**
* Check if an element is under an anchor element
*/
function isDescendantOfAnchor(element) {
do {
if (element.tagName === 'A') {
return true
}
} while(element = element.parentNode)
@srph
srph / index.html
Last active February 7, 2019 06:13
JS/CSS: Animate node on scroll
<h5 class="text-fade-in js-animatable" data-animatable-offset="256" data-animatable-delay="200">Staging</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="324" data-animatable-delay="300">Deep-cleaning</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="324" data-animatable-delay="400">Cosmetic renovations</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="358" data-animatable-delay="500">Decluttering</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="392" data-animatable-delay="600">Landscaping</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="460" data-animatable-delay="700">Painting</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="460" data-animatable-delay="800">Pest control</h5>
<h5 class="text-fade-in js-animatable" data-animatable-offset="494" data-animatable-delay="900">Custom closets</h5>
<div class="photo-cover js-animatable">
@srph
srph / types.ts
Last active January 22, 2019 15:34
qhistory & react-router types
import { Location, LocationState } from 'history';
import { RouteComponentProps as ReactRouteComponentProps } from 'react-router-dom'
export interface RouteComponentProps<Q = { [key: string]: string }> extends ReactRouteComponentProps {
location: Location<LocationState> & {
query: Q
};
}
@srph
srph / index.js
Last active January 22, 2019 02:39
React Router: Nested error 404
// Error404Context.js
export default {Provider, Consumer} = React.createContext()
// Error404Provider.js
class Error404Provider extends React.Component {
state = {
isError: false
}
render() {
@srph
srph / readme.md
Last active May 7, 2019 06:55
React Hook: useFormState
const form = useFormState({ 
  email: '',
  password: ''
})

// returns form.setEmail, form.email, form.setPassword, and form.password
<input value={form.email} onChange={form.setEmail} />
@srph
srph / RouterNavLink.tsx
Created December 2, 2018 06:17
React Router DOM: NavLink activeClassName proxy component
@srph
srph / interceptor-validation-errors.ts
Last active November 25, 2018 08:04
axios: Open up a toast when a validation error occurs
import instance from './instance'
import { toast } from '@app/components/Toast'
import { AxiosRequestConfig, AxiosError } from 'axios';
interface IAxiosInterceptorValidationConfig extends AxiosRequestConfig {
appValidationError?: string | boolean
}
interface IAxiosInterceptorValidationError extends AxiosError {
config: IAxiosInterceptorValidationConfig
@srph
srph / index.ts
Created November 24, 2018 11:11
TS: Check if an array contains the provided subset
function subsetIncludes(array: any[], value: any): boolean {
return Boolean(
array.find(arrayValue => isSubset(arrayValue, value))
)
}
@srph
srph / RouterRoute.tsx
Created November 16, 2018 15:01
React Router v4: Passthrough props Route
import * as React from 'react'
import { Route } from 'react-router-dom'
import { RouteProps } from 'react-router'
interface IRouterRouteProps extends RouteProps {
component: any
}
class RouterRoute extends React.Component<IRouterRouteProps> {
render() {
@srph
srph / Switch.tsx
Created November 16, 2018 14:58
React Router v4: Passthrough props for Switch
import * as React from 'react'
import { Switch } from 'react-router-dom'
interface IRouterSwitch {
children: any
}
class RouterSwitch extends React.Component<IRouterSwitch, {}> {
render() {
const {children, ...rest} = this.props