Skip to content

Instantly share code, notes, and snippets.

View jcarroll2007's full-sized avatar

Jordan Carroll jcarroll2007

View GitHub Profile
@jcarroll2007
jcarroll2007 / bug.jsx
Last active February 4, 2022 14:37
JavaScript Bug Example
function filterAnimals(animals) {
if (!FeatureFlag.releaseTheLions) {
return animals.filter(maybeLeo => maybeLeo.id !== 'lion');
}
}
const AnimalsList: React.VFC = () => {
const animals = [
{
name: 'Leo',
@jcarroll2007
jcarroll2007 / Tests.jsx
Created November 10, 2021 13:28
Creating scalable, testable, and readable React apps: Part 3 Test examples
/**
* Component Test
*/
describe('CharacterCreateForm', () => {
it('should not submit form and show error message if name is null', async () => {
const onSubmitMock = jest.fn()
const { getByTestId, queryByTestId } = render(
<CharacterCreateForm onSubmit={onSubmitMock} />
)
const submitButton = getByTestId('form-submit-button')
@jcarroll2007
jcarroll2007 / CharacterList.tsx
Last active March 23, 2021 12:55
React Architecture Blog Post: Character List component
import React from 'react';
import { Character } from '../../api/types';
import {
Wrapper,
List,
ListItem,
ListItemInfo,
NameWrapper,
IsJediWrapper,
HeaderTypography
@jcarroll2007
jcarroll2007 / CharactersList.tsx
Created March 23, 2021 12:52
React Architecture Blog Post: Character List Container
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { CharacterList } from '../../components/CharacterList'
import { ActionList } from '../../components/ActionList';
import { characterListLoadingSelector, characterListSelector } from '../../redux/selectors';
import { actions } from '../../redux/actions';
interface CharacterListContainerProps {
createCharacterPath: string
}
@jcarroll2007
jcarroll2007 / Characters.tsx
Last active March 23, 2021 12:51
React Architecture Blog Post: Create a Character Modal
import React from 'react';
import { Route } from 'react-router-dom';
import { Page } from '../../components/Page';
import { CharacterListContainer } from '../../containers/CharacterList';
import { CHARACTERS_CREATE } from '../../routes';
import { CharactersCreateView } from '../CharactersCreate';
export const CharactersView: React.FunctionComponent = () => {
return (
<Page>
@jcarroll2007
jcarroll2007 / Views.tsx
Last active September 30, 2020 18:24
React App Structure
<Switch>
<Route path="/users" exact component={UsersView} />
<Route path="/home" exact component={HomeView} />
<Route path="/settings" exact component={SettingsView} />
</Switch>
<Switch>
<Route path="/users" component={UsersList} />
<Route path="/users/create" exact component={CreateUserView} />
<Route path="/users/:id" exact component={EditUserView} />
@jcarroll2007
jcarroll2007 / createRoute.js
Last active June 30, 2020 13:55
A util for creating route paths. It would be great to add types to this.
import invariant from 'invariant'
import { matchPath } from 'react-router'
import { pathToRegexp, compile } from 'path-to-regexp'
import map from 'lodash/map'
import trim from 'lodash/trim'
import flow from 'lodash/flow'
import partialRight from 'lodash/partialRight'
import isString from 'lodash/isString'
import isEmpty from 'lodash/isEmpty'
import { createSymbol } from '../../utils'
@jcarroll2007
jcarroll2007 / cloudSettings
Last active May 9, 2020 10:56
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-01-27T12:30:45.167Z","extensionVersion":"v3.4.3"}
const TitleSubtitleCell => ({ title, subtitle }) => (
<div>
<Title>{title}</Title>
<SubTitle>{subtitle}</SubTitle>
</div>
)
const columns = [{
header:
width: 'grow', // A width props supports custom column sizing
@jcarroll2007
jcarroll2007 / example.js
Last active January 20, 2020 18:17
React Intersection Observer Hook: `useIsElementInView`
import React from 'react'
import useIsElementInView from './useIsElementInView'
export function Example() {
const { ref, isInView } = useIsElementInView()
return (
<div ref={ref}>
{isInView ? 'It is in the view!' : 'Not in view (so you cant really even tell if it works I guess...)'}
</div>