This file contains 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
function isSimpleObject(value: any): boolean { | |
return !!value && value.constructor === Object; | |
} | |
function useMergeState<T>(initialState?: T) { | |
const [mergeState, setMergeState] = isSimpleObject(initialState) | |
? React.useState<T>(initialState as T) | |
: React.useState<Partial<T>>(); | |
const setState = React.useCallback((newState: Partial<T>) => { |
This file contains 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
// Reference "Router.RouteComponentProps" in any file without having to import. | |
// i.e. const MyReactComponent: React.FC<Router.RouteComponentProps> = (props) => (<div>{props.location.pathname}</div>); | |
// The code below goes into a file named "react-router.types.d.ts" this should go in the same directory as "react-app.env.d.ts" or your global definitions. | |
import { RouteComponentProps as IRouteComponentProps } from "react-router-dom"; | |
export interface RouteComponentProps<T = {}> extends IRouteComponentProps<T> {}; | |
export as namespace Router; |
This file contains 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
// Mixin like functionality | |
const textInput = props => ` | |
color: ${props.error ? color.white : color.base}; | |
background-color: ${props.error ? color.alert : color.white}; | |
`; | |
export const Input = styled.input` | |
${textInput} | |
`; |