This repo was deprecated (see new samples section), but due to the popularity of it, we have decided to update all the samples to the newest package versions and best practices, sample that are already uptodate: 00, 01, 02, 03, 04, 05, 06, 07, 08, rest of sample work in progress, if you need to progress on more advanced sample please check our React By Sample and Redux By Sample repos. Thanks for your support and stars ;-).
We have created a new set of updated samples.
Typescript
React:
https://github.com/Lemoncode/react-by-sample
React + Redux:
https://github.com/Lemoncode/redux-by-sample
ES6
Work in progress
React:
https://github.com/Lemoncode/react-by-sample-es6
React + Redux:
https://github.com/Lemoncode/redux-by-sample-es6
The goal of this project is to provide a set of simple samples, providing and step by step guide to start working with React and Typescript. Characteristics:
- Bundling based on webpack.
- React + Typescript based.
- Simple navigation using react-router.
- Managing async calls and updates.
- Using Redux library.
- Handling async calls via Redux-Thunk + Redux Saga.
- Adding unit testing support.
- Implementing Lazy Loading.
- Future enhancements:
- Using Immutablejs.
- Using React Hot Loader.
Some months ago this project started as something internal... let's create some simple samples that cover react / redux / typescript scenarios that could serve as a guidance and reference in the future... now, we and other developers are using this repo as quick by sample guidance. We keep on adding more samples to it, but we have found that older samples need some updates / refactoring.
Are you interested in contributing into this project? If that's the case don't hesitate contacting us.: call for contributors.
- Install NodeJS
npm install webpack -g
- Installs webpacknpm install tsd -g
- Installs tsd- Download this repo
- Open the command line of your choice and cd to the root directory of this repo on your machine
npm install
- Installs packagesnpm start
- Builds the project and launch a lite web server (webpack-devserver).- Navigate to http://localhost:8080/ if your browser doesn't open automatically.
We have tested in:
Bundling + npm start based on webpack.
Hello world, simples react render sample.
Creating a common header and about page react components.
Creating a "members" page, adding navigation using react-router.
Create a read only list component (table >> tr >> td), reading list of members from a fake api and dumping it into component state.
Breaking the list component into two: list and row compomenent, member row entity passed via props.
Members fake api replaced with async call to api github to retrieve list of members of a given team.
In this sample we will add a link in the members page that will navigate to a "new member page". This new page will display a form where you have to enter the avatar url, login and id of a new member (just supossing we can edit that info).
Edit a given member, here we learn how to add params to a navigation link and how to obtain them from a component.
Validation performed so far:
- Login: required, must be a string (at least length 3).
Added Redux support, isolated state into Redux reducers, implement load, save, basic validation cycle. This sample uses the fake api, in following samples we will call async operations and fitting them into Redux architecture.
Display a busy indicator when an ajax request is in progress.
We have created here:
- A component that will take care of showing / displaying the busy indicator (spinner).
- A reducer that will take care of dispatching http requests in progress / completed.
- A http middleware that dispatch HttpCallCompleted action when http request is completed.
We have updated MemberAPI to use the http helper / wrapper.
Testing libraries:
We added a Karma configuration on Webpack, that runs every '.spec' inside src folder and subfolders. This configuration allows debugging with Typescript.
With Mocha we can describe our tests and it adds support for async tests.
Chai is for assertions.
With Deep free we ensures that initial states in reducers are immutable.
Testing libraries, previous libraries and:
Sinon join Mocha allow us async action tests.
Testing libraries, previous libraries and:
Enzyme provide an easy way to isolate, manipulate, traverse and assert React Components.
Redux Saga it's an interesting alternative for redux-thunk, worth to take a look:
Use webpack require.ensure to load routes on demand.
Create two custom middlewares uiNotificationMiddleware and navigationMiddleware
React Hot loader allows us to introduce changes in the application source code meanwhile we are running our web server and get the changes into our page without having to reload the browser and not losing the application state.
Redux dev tool is a chrome add-on that allows us to browse the state, replay actions, inject actions, export / import state...
We are a team of long-term experienced freelance developers, established as a group in 2010. We specialize in Front End technologies and .NET. Click here to get more info about us.
For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend