Skip to content

Instantly share code, notes, and snippets.

View dancingshell's full-sized avatar
🥨

Kaitlin Jaffe dancingshell

🥨
View GitHub Profile
@dancingshell
dancingshell / TypedHOC.tsx
Last active May 3, 2020 03:25
React & Typescripts: A typed HOC wrapper like react-redux connect
type HOCPropInjector<InjectedProps = {}> = <OwnProps>(
Component: React.FC<OwnProps> | React.ComponentClass<OwnProps, {}>
) => React.FC<OwnProps & Omit<OwnProps, keyof InjectedProps>>
type CollectProps<ReturnProps, TParam> = (
injectorParam: TParam,
props: any
) => ReturnProps
type HOCFunctionWrapper<Param, InjectedProps = {}> = <CollectedProps>(
@dancingshell
dancingshell / ReactPortalWrapper.jsx
Created June 26, 2018 01:49
React Portal backwards compatible to v0.14
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
const isReact16 = ReactDOM.createPortal !== undefined;
export default class Portal extends React.Component {
static propTypes = {
children: PropTypes.node,
show: PropTypes.bool
@dancingshell
dancingshell / currentUser-roleResolver.js
Last active October 21, 2016 21:58
Current User from Role Resolver
/**
After reading about all the issues loobackContext.getCurrentContext() I was getting concerned.
In my experience with role resolvers, the AccessContext is not vulnerable to the same issues of dropping context.
My thinking was to grab the currentUser from the AccessConext in a roleResovler and set it on the instance
which would then be accessable in the operation hooks without have to use loopback-context. More testing needed.
**/
// register role resolver
Role.registerResolver( 'currentUser', function( role, context, cb ) {
var currentUser;