Skip to content

Instantly share code, notes, and snippets.

@Calvein
Last active June 17, 2021 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Calvein/77872ee147546d0a1ed8eba2b2c4dcf2 to your computer and use it in GitHub Desktop.
Save Calvein/77872ee147546d0a1ed8eba2b2c4dcf2 to your computer and use it in GitHub Desktop.

React/Redux architecture

Tools

Libraries

Core libraries

Libraries that I use and will re-use

  • Recompose: Utilities for components and HOC
  • Reselect: To manage how the data is retrieve from the state, it also memoized the calls to be more efficient
  • redux-api-middleware: Best way to get & store data
  • Formik: Easier & smaller than Redux Form, you could think that it would make sense to use it since you're using Redux but we had many issues with the later
  • Pose & Popmotion: EAsy animations
  • Jest: Testing library, it's built-in Create React app
  • Enzyme: Test React component à la jQuery

Libraries that I want to try

React tips

  • Don't abuse HOC, I find "Function as Child Components" much nicer & simpler when applicable

Redux tips

  • Store only string & number, no complex object like Date (or worse, moment object, use date-fns if possible)
  • If you have to send data back to an API, don't modify the data you're getting from it. It'll prevent you the headaches of transforming the input data and the output one

Folder architecture

I structure my code in an /app folder likewise:

app
├─ components
├─── ReusableComponent
├─ my-feature
│  ├─ components
│  ├─── ReusableComponentForThisFeature
│  ├─ MyComponent
│  └─── index.js
├─ MySubComponent
│  ├─ index.js
│  └─ styles.css
├─ index.js
└─ styles.css

Storybook-driven development

I create a story per component that I will call Main & a story per each sub-component, e.g:

MyComponent
├─ stories
│  └─ index.js
├─ MySubComponent
│  ├─ index.js
│  └─ styles.css
├─ index.js
└─ styles.css
import React from 'react'
import { storiesOf } from '@storybook/react'

import MyComponent from '../'
import MySubComponent from '../index'

storiesOf('MyComponent', module)
  .add('Main', () => (
  	<MyComponent />
  ))	
  .add('MySubComponent', () => (
    <MySubComponent />
  ))

Storybooks has many addons, here are the ones I'm using:

Use react-stubber to stub your containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment