This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* I want to key array by 'id' | |
* | |
* FROM: [{id: 'a', name: 'A'}, {id: 'b', name: 'B'}] | |
* TO: { a: {id: 'a', name: 'A'}, b: {id: 'b', name: 'B'} } | |
* | |
*/ | |
const arr = [{id: 'a', name: 'A'}, {id: 'b', name: 'B'}] as const |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Problem: defining object with interfaces grant autocomplete but also widen all types (e.g. `true` becomes `boolean`) | |
* Defining object with `as const` infers all the narrowed types but looses autocomplete | |
* Solution: Create utility function with constrained generic type parameters. More info [here](https://kentcdodds.com/blog/how-to-write-a-constrained-identity-function-in-typescript) | |
*/ | |
interface ISchema { | |
id: string; | |
description: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:14.15-alpine as base | |
WORKDIR /home/app | |
COPY package.json yarn.lock ./ | |
# ---prepare dependencies--- | |
FROM base as dependencies | |
# install production dependencies | |
RUN yarn install --production --frozen-lockfile | |
RUN mv node_modules prod_node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default function withPropsChecker(WrappedComponent) { | |
return class PropsChecker extends React.Component { | |
componentWillReceiveProps(nextProps) { | |
Object.keys(nextProps) | |
.filter(key => { | |
return nextProps[key] !== this.props[key]; | |
}) | |
.map(key => { |