Code Monkey home page Code Monkey logo

mod-5-react-resources's Introduction

Hello everyone and welcome to Module 5!

Below are some helpful resources that will help you when building out your final projects

  1. Please remember that the setState method in React is asynchronous.

  2. You've likely seen or will see the warning that each child in an array or iterator should have a unique key prop. Example:

this.state.hogs.map((hog, index) => (
  {/*AVOID THIS*/}
  <HogTile key={index} />
  {/*Do this instead*/}
  <HogTile key={hog.id} />
))

Essentially, React is telling you that any child components should have a unique identifier or key prop. When passing your components key props, avoid using the index while you're iterating as a key as it is an anti-pattern.

  1. You may also want to be cautious of setting the initial state of a component based on props.
class Hog extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
    //try to avoid this as it violates single source of truth
      hogs: props.hogs
    }
  }
}
  1. Semantic UI for React is a great CSS library written specifically for React. Make sure you read the usage section of the docs to see how to incorporate it into your React projects. Make sure you're reading the docs for the react version of semantic, not the vanilla JS one. Their other library uses jQuery which does not play well with React at all.

  2. Please review error handling in fetch and familiarize yourself with this.

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
  })
  .then( json => {
    this.props.dispatch(doSomethingWithResult(json)) 
  })
  .catch( err => {
    err.text().then( errorMessage => {
      this.props.dispatch(displayTheError(errorMessage))
    })
  })

View Some Useful Tools for Writing React on Learn.co and start learning to code for free.

mod-5-react-resources's People

Contributors

realandrewcohn avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.