Skip to content

Instantly share code, notes, and snippets.

Marcus SimpleCookie

View GitHub Profile
@SimpleCookie
SimpleCookie / useRelativeClick.tsx
Created Apr 21, 2020
useRelativeClick React Hook
View useRelativeClick.tsx
import { useEffect } from "react";
export function useRelativeClick(ref, callback: (inside: boolean) => any) {
function handleClickOutside(event) {
if (ref.current) {
const insideClick = ref.current.contains(event.target)
callback(insideClick)
}
}
View tslint.json
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": ["config/**/*.js", "node_modules/**/*.ts"]
},
"rules": {
"ordered-imports": [
false,
{
"import-sources-order": "any",
@SimpleCookie
SimpleCookie / reducer.jsx
Created Apr 11, 2020
Redux reducer example
View reducer.jsx
const reducer = (state = initialState, action) =>
handlers[action.type] ? handlers[action.type](state, action) : state
const setFooToTrue = () => ({
...state,
foo: true,
})
const handlers = {
"someAction": setFooToTrue,
@SimpleCookie
SimpleCookie / cloudSettings
Last active Jun 9, 2020
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2020-06-09T07:29:00.207Z","extensionVersion":"v3.4.3"}
You can’t perform that action at this time.