A tutorial application made with React, React Router and Airflux. The goal is to create a small application covering all the concepts of React and Flux.
npm install
gulp
Gulp will then start a server on port 8001. To access it, go to http://localhost:8001
The project is built around gulp task manager responsible for:
- building your application with Browserify
- building the CSS
- starting a livereload server on port 8001
- One base React component, rendered into the DOM
- Base setup of an application, using the state with an input
- Displaying a static list of movies
- Editing the list of movies
- Using stores to keep the list of movies
- Creating new routes for your application using React Router
- Asynchronous call to a web service
React Application, React Components, State
- app.js: renders HomeScreen into the DOM
- HomeScreen.jsx: main component of the application
State
- We create several components, all tied together in the
Home
component BasicReactSample
component has a statechangeName
callback modifies the state- An input is mapped to the state value, and triggers the
changeName
callback
ValueLink
BasicReactSample
has alinkState
function- An input is mapped to the state value using a the ValueLink object provided by
linkState
Simple React Router, Passing Props, Proptypes
- app.js now defines routes. Each route is simply mapped to a React component
- Home.jsx uses the Router for the NavBar
Home
component is used for the scaffolding of the application, and render the component selected by the routeMovieList
iterates through a list of movies, rendering aMovie
component for each one, passing the movie through propsMovie
has a proptyes static attribute to validates the props
Passing callbacks from a parent component to its child
MovieForm
was added to add moviesMovieList
has function to add movies to its state..- .. and passes the function to
MovieForm
- Flux Stores and action
- Maping the state of a store to the state of a component
MovieActions
defines the Flux actionsMovieStore
create the store containing the moviesMovieList
is connected to theMovieStore
to get its data
- Adding another action into the mix
Home
listens to this action to display notifications
Routing with params, Seperating the loading logic from display, asynchronous Flux actions
MovieEditor
is now a seperate component and has a route..- .. it handles the loading of the movie to edit..
- and passes it through
props
toMovieForm
find
is an asynchronous action
AJAX call using fetch
- All data are coming from a web service (started together with gulp)
api
package defines the web services calls usingfetch
API- Actions are now directly mapped to these calls returning Promises