Skip to content

Instantly share code, notes, and snippets.

@gitmathub
Last active September 23, 2019 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitmathub/c4477c794d7d3caa3a1a2f6012241892 to your computer and use it in GitHub Desktop.
Save gitmathub/c4477c794d7d3caa3a1a2f6012241892 to your computer and use it in GitHub Desktop.
Setup a React Project

Setup a React Project

Links and resources for building a react project

Project build up strategy

Taken from: React Docs: Thinking in React

  1. Design Mock (scribble), JSON data (data model)
  2. Break The UI Into A Component Hierarchy
    • draw boxes in the mockup
    • name all boxes
    • think in parents and children
    • props and state flowing down the hierarchy
  3. Build A Static Version in React
    • No state, no interaction: just static
    • smaller projects: top down
    • big projects: bottom-up with tests
  4. Minimal (but complete) UI State
  5. State and Component
  6. Add Inverse Data Flow
    • interaction of the user updates state
    • state might be propagated upwards
    • keyword: double data binding

Understand difference props and state

  • Is it passed in from a parent via props? If so, it probably isn’t state.
  • Does it remain unchanged over time? If so, it probably isn’t state.
  • Can you compute it based on any other state or props in your component? If so, it isn’t state.

Where does the state belong to?

  • Identify every component that renders something based on that state.
  • Find a common owner component (a single component above all the components that need the state in the hierarchy).
  • Either the common owner or another component higher up in the hierarchy should own the state.
  • If you can’t find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common owner component.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment