Skip to content

Instantly share code, notes, and snippets.

View benmvp's full-sized avatar

Ben Ilegbodu benmvp

View GitHub Profile
@benmvp
benmvp / App.js
Created March 30, 2020 18:09
React FUNdamentals, Step 2 - Query Field Exercise
import React, { useState } from 'react'
const App = () => {
const [inputValue, setInputValue] = useState('')
const [isUpper, setIsUpper] = useState(false)
return (
<main>
<h1>Giphy Search!</h1>
@benmvp
benmvp / text.module.scss
Created January 18, 2020 00:02
Trying to figure out how to programmatically generate CSS class names using SASS + CSS Modules + babel-react-css-modules
$colors: ("white": $white, "yellow": $yellow, "green": $green, "blue": $blue);
@each $name, $color in $colors {
// this programmatically generates 4 class namaes in the resultant css.
// but when Babel parses the module to pull out the class names, it just
// gets "bg-color-#${name}" since postcss-scss doesn't compile the SCSS
// (https://github.com/postcss/postcss-scss) when used with babel-react-css-modules
// (https://github.com/gajus/babel-plugin-react-css-modules#configurate-syntax-loaders)
.bg-color-#{$name} {
background-color: #{$color};
@benmvp
benmvp / Text.jsx
Last active January 17, 2020 18:33
Trying to extend my Text component props from the props that come from the specified HTML element using TypeScript generics
import React from 'react'
// React.ElementType from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8a31a2fe9e8417d47550db09e5f9f50fd09a8e60/types/react/index.d.ts#L67
interface Props<C extends React.ElementType> {
children: React.ReactNode
component?: C;
gutterBottom?: boolean;
className?: string;
style?: CSSProperties;
import {mapValues} from 'lodash';
import {Sdk, SdkConfig} from './types';
import request from './request';
import * as users from './users';
export * from './constants';
const DEFAULT_API_URL = 'https://www.eventbriteapi.com/v3';
@benmvp
benmvp / DummyAddressForm.jsx
Created November 16, 2017 05:32
How can I use enzyme shallow rendering to assert props being passed to TextInput/Label and not helper TopSection/BottomSection?
import React from 'react';
import TextInput from './TextInput';
import Label from './Label';
const TopSection = ({fields: {firstName, lastName}}) => (
<fieldset>
<div>
<Label>First Name</Label>
<TextInput name="firstName" value={firstName} />
// pass the children back to the component to be used
// in the final render
const Enhancer = ({render, children, foo}) => (
<div>{render(foo * 2, children)}</div>
)
// ViewComp uses both `render` & `children` 🙃
const ViewComp = () => (
<Enhancer foo={11} render={(value, children) => (<div>{value} - <span>{children}</span></div>)}>
Here's some children content
@benmvp
benmvp / dual-export-component.jsx
Last active September 25, 2017 21:23
Searching for a similar pattern for render props approach!
// This is what gets tested because it doesn't rely on any of
// the *magic* that may be in `withFoo` like reading context.
// The test just needs to pass in a valid `foo` prop which would've
// come from `withFoo`.
export const MyComponent = ({foo}) => (
<div>{foo}</div>
)
// This what actually gets used in the app!
export default withFoo(MyComponent)
@benmvp
benmvp / hoc.js
Last active August 29, 2017 06:20
Need Dynamic HOC Flow help
const myHOC = <Props: {}>(
Component: React.ComponentType<{}>
): React.ComponentType<Props> (
(props: Props) = {
let handlers = genDynamicAdditionalProps(props.eventName)
// The keys in `additionalProps` are dependent upon `props.eventName` value
// The values in `additionalProps` are all functions
let propsToPassThru = {...props}