Skip to content

Instantly share code, notes, and snippets.

View kag359six's full-sized avatar

Kristopher Guzman kag359six

View GitHub Profile
import React, { useState } from "react";
import { Form } from "semantic-ui-react";
export const TextField = ({
onSave,
icon,
value,
loading,
error,
...props
@kag359six
kag359six / asyncsaveinput.js
Last active April 27, 2020 14:00
async save input
import React, { useState } from "react";
import { Form } from "semantic-ui-react";
export const TextField = ({
onSave,
icon,
value,
loading,
...props
}) => {
import React from "react";
import { render } from "react-dom";
import { Container, Form } from "semantic-ui-react";
import { TextField } from "./TextField";
// resolves to new value in 2 seconds
const mockSave = val =>
new Promise(resolve => setTimeout(() => resolve(val), 2000));
const App = () => (
@kag359six
kag359six / baseTextField.js
Created April 27, 2020 13:16
Base for custom text field using semantic UI
import React, { useState } from "react";
import { Form } from "semantic-ui-react";
// We use Form.Input because it gives us some
// nice benefits (like error messages). You will want
// to wrap this around a <Form/> component so it displays properly
export const TextField = ({icon, ...props }) => {
return (
<React.Fragment>
<Form.Input
@kag359six
kag359six / changed_response.js
Created March 16, 2020 12:58
changed response
/****** ORIGINAL RESPONSE DEFINITION *******/
type GetUserResponse = {
name: string
phone: number
family: User[]
}
/******** NEW RESPONSE DEFINITION *******/
@kag359six
kag359six / typdef_for_endpoint.js
Last active March 16, 2020 12:55
example type definition for an endpoint
type GetUserRequest = {
id: string
}
type GetUserResponse = {
name: string
phone: number
family: User[]
}
@kag359six
kag359six / plainComponent.js
Created March 9, 2020 09:51
React Component w/o TypeScript
export class NameProvider extends React.Component {
state = { name: 'Piotr' };
render() {
return this.props.children(this.state);
}
}
@kag359six
kag359six / typescriptComponent.js
Created March 9, 2020 09:49
React Component w/ TypeScript
interface NameProviderProps {
children: (state: NameProviderState) => React.ReactNode;
}
interface NameProviderState {
readonly name: string;
}
export class NameProvider extends React.Component<NameProviderProps, NameProviderState> {
readonly state: NameProviderState = { name: 'Piotr' };
@kag359six
kag359six / FlexTypes.js
Created February 4, 2020 14:37
types for flex component
/*** FLOW TYPES ***/
type FlexProps = {
children?: any,
className?: string,
container?: boolean,
/****** Container Props ********/
flexDirection?: 'row' | 'column',
justifyContent?:
| 'flex-start'
@kag359six
kag359six / Flex.js
Created February 4, 2020 14:31
Flex Component
export const Flex = (props) => (
<div
className={props.className}
style={{
display: props.container ? 'flex' : 'block',
justifyContent: props.justifyContent || 'flex-start',
flexDirection: props.flexDirection || 'row',
flexGrow: props.flexGrow || 0,
flexBasis: props.flexBasis || 'auto',
flexShrink: props.flexShrink || 1,