Skip to content

A React Github searcher utility with a focus on idiomatic principles and the component life cycle

License

Notifications You must be signed in to change notification settings

TucsonReactJS/primer

Repository files navigation

primer

A React primer repo with focus on idiomatic principles and the component life cycle. This repo contains a simple React Github search utility built using React current best practices (to the extent of my knowledge). PR's and comments are welcome if I get it wrong!

Dependencies Status devDependency Status

Fluxible branch

This branch takes the master branch and makes it an Isomorphic React application using the awesome fluxible framework by Yahoo!. This is still a WIP, but stay tuned as I finish porting it and making it work.

Build

An idomatic React application will use a build system to transpile JSX into JS for running inside the browser. This project uses gulp and webpack to accomplish this task. To build this project type the following in your shell of choice-

  • git clone https://github.com/TucsonReactJS/primer.git - Clone the repo
  • npm install -g gulp - Install gulp globally
  • cd primer - change into the primer directory
  • npm install - install dependencies
  • gulp - build and watch using nodemon

ES6

React 0.13 introduces the ability to write your React application using standard ES6 syntax. The old React.createClass method is still supported, but in order to be idiomatic and future-proof, this repo uses the newly introduced syntax. The ES6 code is transpiled to ES5 using babel.

Architecture overview

Views

The component is built as a Single-Page Application or SPA. There is one index.html file, which contains simple meta tags and stylesheets, and provides a single div to mount our React application.

client.js

The client.js file is the main entry point in our application and does a few key things.

  • Gets a reference to the main app.jsx component
  • Gets a reference to the 'app' DOM node
  • Calls React.render(<App/>,mountNode) to render the application into the node

app.jsx

The app.jsx file is the top-level component of out React application. It renders a container, row and an instance of RepoListContainer . It uses the componentWillMount as an example of performing some work before the render method is called. In this case a simple isMobile() check is done, and the state is set accordingly.

repo_list/repo_list_container.jsx

The RepoListContainer is a container component. It is responsible for fetching data from the remote endpoint, and passing it down to the it's child components. It uses componentDidMount and componentWillUnmount to fetch data and clean up a debounce method. It has a RepoList and RepoListFilter as children.

repo_list/repo_list_filter.jsx

The RepoListFilter is responsible for taking the users input to change the sort and a simple 'stars' filter. It uses shouldComponentUpdate to prevent any unnecessary rendering.

repo_list/repo_list.jsx

The RepoList is responsible for mapping and rendering a list of RepoListItem. Additionally, this component uses the componentWillReceiveProps lifecycle method to compute whether a particular repo has trended up or down since the last request.

repo_list/repo_list_item.jsx

The RepoListItem is responsible for rendering a single repo item. It uses TrendingUpArrow and TrendingDownArrow components to show trending status. The RepoListItem uses componentWillUpdate and componentDidUpdate to access the raw DOM element and pass it to an animation library. If the previous or upcoming props don't match, then the item will "transition" into the change by sliding out. This a little contrived, but is helpful to visualize the lifecycle method.

common/trending_up_arrow.jsx

A simple styled up arrow

common/trending_down_arrow.jsx

A simple styled down arrow

About

A React Github searcher utility with a focus on idiomatic principles and the component life cycle

Resources

License

Stars

Watchers

Forks

Packages

No packages published