tricinel
7 years ago
107 changed files with 5160 additions and 2574 deletions
@ -0,0 +1,5 @@ |
|||
Thank you for the PR! Contributors like you keep React awesome! |
|||
|
|||
Please see the Contribution Guide for guidelines: |
|||
|
|||
https://github.com/reactjs/reactjs.org/blob/master/CONTRIBUTING.md |
@ -0,0 +1,139 @@ |
|||
# Contributing |
|||
|
|||
Thank you for your interest in contributing to the React Docs! |
|||
|
|||
## Code of Conduct |
|||
|
|||
Facebook has adopted a Code of Conduct that we expect project |
|||
participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) |
|||
so that you can understand what actions will and will not be tolerated. |
|||
|
|||
## Guidelines for Text |
|||
|
|||
**Different sections intentionally have different styles.** |
|||
|
|||
The documentation is divided into sections to cater to different learning styles and use cases. When editing an article, try to match the surrounding text in tone and style. When creating a new article, try to match the tone of the other articles in the same section. Learn about the motivation behind each section below. |
|||
|
|||
**[Tutorial](https://reactjs.org/tutorial/tutorial.html)** is relatively informal, and is designed for people who prefer a hands-on approach to learning, and can tolerate skipping theory in favor of practice. Its goal is to give the reader a feel for a typical React workflow rather than to explain fundamentals in detail. Here we focus on *what* to do and spend less time on *how* or *why* we did it. It is extremely important to do a lot of hand-holding and unambiguously describe every single change. It should be possible for a beginner to mechanically follow every instruction, and still get to a working tic-tac-toe game. |
|||
|
|||
**[Quick Start](https://reactjs.org/docs/hello-world.html)** is designed to introduce fundamental concepts in a step-by-step way. Each individual article in Quick Start builds on the knowledge from the previous ones, so make sure not to add any "cyclical dependencies" between them. It is important that the reader can start with the first article and work their way to the last Quick Start article without ever having to "look ahead" for a definition. This explains some ordering choices (e.g. that state is explained before events, or that "thinking in React" doesn't use refs). Quick Start also serves as a reference manual for React concepts, so it is important to be very strict about their definitions and relationships between them. This is, for example, why we introduce elements before components. Resist adding too much detail to Quick Start articles. They intentionally don't cover all corner cases, and focus on establishing firm foundations. |
|||
|
|||
**[Advanced Guides](https://reactjs.org/docs/jsx-in-depth.html)** are deep dives into topics that aren't essential for a beginner developer but that everyone bumps into sooner or later. They don't have a specific order, and target more experienced developers. If you have a set of recipes fitting a particular use case, and those recipes aren't opinionated (most React users would agree on them), this is the place to add them. |
|||
|
|||
**[Reference](https://reactjs.org/docs/react-api.html)** is organized by APIs rather than concepts. It is intended to be exhaustive. Any corner cases or recommendations that were skipped for brevity in Quick Start or Advanced Guides should be mentioned in the reference documentation for the corresponding APIs. |
|||
|
|||
**[Contributing](https://reactjs.org/docs/how-to-contribute.html)** should stay up-to-date and be friendly to relatively experienced developers. |
|||
|
|||
**[FAQ](https://reactjs.org/docs/faq-ajax.html)** has a more conversational tone than the other sections. Here, it's fine to include some content that's not primarily concerned with React, as long as React users are overwhelmingly interested in it (e.g. recommendations on directory structure). It's also okay to show more than a single way to do something in the FAQ, and briefly discuss the tradeoffs. The FAQ prioritizes unblocking people with a working solution over explaining concepts in detail, and can be more opinionated than the rest of the docs, even providing popular library recommendations. |
|||
|
|||
**Try to follow your own instructions.** |
|||
|
|||
When writing step-by-step instructions (e.g. how to install something), try to forget everything you know about the topic, and actually follow the instructions you wrote, a single step at time. Often you will discover that there is implicit knowledge that you forgot to mention, or that there are missing or out-of-order steps in the instructions. Bonus points for getting *somebody else* to follow the steps and watching what they struggle with. Often it would be something very simple that you have not anticipated. |
|||
|
|||
## Guidelines for Code Examples |
|||
|
|||
### Syntax |
|||
|
|||
**Prefer JSX to `createElement`.** |
|||
|
|||
Ignore this if you're specifically describing `createElement`. |
|||
|
|||
**Use `const` where possible, otherwise `let`. Don't use `var`.** |
|||
|
|||
Ignore this if you're specifically writing about ES5. |
|||
|
|||
**Don't use ES6 features when equivalent ES5 features have no downsides.** |
|||
|
|||
Remember that ES6 is still new to a lot of people. While we use it in many places (`const` / `let`, classes, arrow functions), if the equivalent ES5 code is just as straightforward and readable, consider using it. |
|||
|
|||
In particular, you should prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. However, you *should* use arrow functions where they provide a tangible improvement (such as preserving `this` context inside a component). Consider both sides of the tradeoff when deciding whether to use a new feature. |
|||
|
|||
**Don't use features that aren't standardized yet.** |
|||
|
|||
For example, **don't** write this: |
|||
|
|||
```js |
|||
class MyComponent extends React.Component { |
|||
state = {value: ''}; |
|||
handleChange = (e) => { |
|||
this.setState({value: e.target.value}); |
|||
}; |
|||
} |
|||
``` |
|||
|
|||
Instead, **do** write this: |
|||
|
|||
```js |
|||
class MyComponent extends React.Component { |
|||
constructor(props) { |
|||
super(props) |
|||
this.handleChange = this.handleChange.bind(this); |
|||
this.state = {value: ''}; |
|||
} |
|||
handleChange(e) { |
|||
this.setState({value: e.target.value}); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
Ignore this rule if you're specifically describing an experimental proposal. Make sure to mention its experimental nature in the code and in the surrounding text. |
|||
|
|||
### Style |
|||
|
|||
- Use semicolons. |
|||
- No space between function names and parens (`method() {}` not `method () {}`). |
|||
- When in doubt, use the default style favored by [Prettier](https://prettier.io/playground/). |
|||
|
|||
### Highlighting |
|||
|
|||
Use `js` as the highlighting language in Markdown code blocks: |
|||
|
|||
```` |
|||
```js |
|||
// code |
|||
``` |
|||
```` |
|||
|
|||
Sometimes you'll see blocks with numbers. |
|||
They tell the website to highlight specific lines. |
|||
|
|||
You can highlight a single line: |
|||
|
|||
```` |
|||
```js{2} |
|||
function hello() { |
|||
// this line will get highlighted |
|||
} |
|||
``` |
|||
```` |
|||
|
|||
A range of lines: |
|||
|
|||
```` |
|||
```js{2-4} |
|||
function hello() { |
|||
// these lines |
|||
// will get |
|||
// highlighted |
|||
} |
|||
``` |
|||
```` |
|||
|
|||
Or even multiple ranges: |
|||
|
|||
```` |
|||
```js{2-4,6} |
|||
function hello() { |
|||
// these lines |
|||
// will get |
|||
// highlighted |
|||
console.log('hello'); |
|||
// also this one |
|||
console.log('there'); |
|||
} |
|||
``` |
|||
```` |
|||
|
|||
Be mindful that if you move some code in an example with highlighting, you also need to update the highlighting. |
|||
|
|||
Don't be afraid to often use highlighting! It is very valuable when you need to focus the reader's attention on a particular detail that's easy to miss. |
@ -0,0 +1,16 @@ |
|||
--- |
|||
id: articles |
|||
title: Articles |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/articles.html |
|||
--- |
|||
|
|||
- [React How-to](https://github.com/petehunt/react-howto) - Pete Hunt's guide to the React ecosystem. |
|||
- [9 things every React.js beginner should know](https://camjackson.net/post/9-things-every-reactjs-beginner-should-know) - Cam Jackson's guide for beginners. |
|||
- [React "Aha" Moments](https://tylermcginnis.com/react-aha-moments/) - Tyler McGinnis' article on his collection of "Aha" moments with React. |
|||
- [You're missing the point of React](https://medium.com/@dan_abramov/youre-missing-the-point-of-react-a20e34a51e1a) - Dan Abramov's article about the best parts of React. |
|||
- [Timeline for Learning React](https://daveceddia.com/timeline-for-learning-react/) - Dave Ceddia's reccommended timeline for learning React and the React ecosystem. |
|||
- [Simple React Development in 2017](https://hackernoon.com/simple-react-development-in-2017-113bd563691f) - Joshua Comeau's guide to showcase how easy it can be to start modern React development. |
|||
- [React FAQ](https://reactfaq.site/) - An external site with articles that try to answer frequently asked questions about React. |
|||
- [Visual Guide to State in React](https://daveceddia.com/visual-guide-to-state-in-react/) - Dave Ceddia's visual guide to React state. |
@ -0,0 +1,33 @@ |
|||
--- |
|||
id: courses |
|||
title: Courses |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/courses.html |
|||
--- |
|||
|
|||
## Free Courses |
|||
|
|||
- [Codecademy: React 101](https://www.codecademy.com/learn/react-101) - Codecademy's introductory course for React. |
|||
|
|||
- [Egghead.io: Start Learning React](https://egghead.io/courses/start-learning-react) - This series will explore the basic fundamentals of React to get you started. |
|||
|
|||
- [React Armory: Learn React by Itself](https://reactarmory.com/guides/learn-react-by-itself) - With React Armory, you can learn React without the buzzwords. |
|||
|
|||
- [The Road to Learn React](https://www.robinwieruch.de/the-road-to-learn-react/) - Build a real world application in plain React without complicated tooling. |
|||
|
|||
## Paid Courses |
|||
|
|||
- [Egghead.io](https://egghead.io/browse/frameworks/react) - Short instructional videos on React and many other topics. |
|||
|
|||
- [Frontend Masters](https://frontendmasters.com/courses/) - Video courses on React and other frontend frameworks. |
|||
|
|||
- [Fullstack React](https://www.fullstackreact.com/) - The up-to-date, in-depth, complete guide to React and friends. |
|||
|
|||
- [Pure React](https://daveceddia.com/pure-react/) - A step-by-step guide to mastering React. |
|||
|
|||
- [React for Beginners](https://reactforbeginners.com/) - Learn React in just a couple of afternoons. |
|||
|
|||
- [React Training: Advanced React.js](https://courses.reacttraining.com/p/advanced-react) - Take your React skills to the next level. |
|||
|
|||
- [Tyler McGinnis](https://tylermcginnis.com/courses) - Tyler McGinnis provides access to his courses for a monthly fee. Courses include "React Fundamentals" and "Universal React". |
@ -1,5 +1,22 @@ |
|||
--- |
|||
permalink: docs/examples.html |
|||
layout: redirect |
|||
dest_url: https://github.com/facebook/react/wiki/Examples |
|||
id: examples |
|||
title: Example Projects |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/examples.html |
|||
--- |
|||
|
|||
There are many example projects created by the React community. Feel free to add your own project. If you add a project, please commit to keeping it up to date with the latest versions of React. |
|||
|
|||
|
|||
* **[Calculator](https://github.com/ahfarmer/calculator)** Implementation of the iOS calculator built in React |
|||
* **[Emoji Search](https://github.com/ahfarmer/emoji-search)** Simple React app for searching emoji |
|||
* **[Github Battle App](https://github.com/ReactTraining/react-fundamentals/tree/hosting)** Battle two Github users and see the most popular Github projects for any language. |
|||
* **[Haskell Websockets React Game of Score](https://www.fpcomplete.com/user/dschalk/Websockets%20Game%20of%20Score):** React with a Haskell websockets server. |
|||
* **[K5 Showcase](https://showcase.cloud.global.fujitsu.com):** Sample applications for React.js and Flux. |
|||
* **[React Powered Hacker News Client](https://github.com/insin/react-hn)** A React & react-router-powered implementation of Hacker News using its Firebase API. |
|||
* **[Pokedex](https://github.com/alik0211/pokedex)** The list of Pokémon with live search |
|||
* **[Progressive Web Tetris](https://github.com/skidding/flatris)** Besides a beautiful, mobile-friendly implementation of Tetris, this project is a playground for integrating and experimenting with web technologies. |
|||
* **[Product Comparison Page](https://github.com/Rhymond/product-compare-react)** Simple Product Compare page built in React |
|||
* **[Hacker News Clone React/GraphQL](https://github.com/clintonwoo/hackernews-react-graphql)** Hacker News clone rewritten with universal JavaScript, using React and GraphQL. |
|||
* **[Reddit Mobile](https://github.com/reddit/reddit-mobile)** Reddit's mobile platform. |
|||
|
@ -0,0 +1,19 @@ |
|||
--- |
|||
id: external-resources |
|||
title: External Resources |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/external-resources.html |
|||
--- |
|||
|
|||
There are many wonderful curated resources the React community has put together. |
|||
|
|||
- [Reactiflux](https://www.reactiflux.com/) - A community of 20,000+ React developers. They keep a well curated [learning section](https://www.reactiflux.com/learning/). |
|||
|
|||
- [React-Redux Links](https://github.com/markerikson/react-redux-links) - Mark Erikson's highly curated list of tutorials and resources for React/Redux/ES6 and more. |
|||
|
|||
- [Awesome React](https://github.com/enaqx/awesome-react) - A collection of awesome things regarding React ecosystem. |
|||
|
|||
- [Awesome React Components](https://github.com/brillout/awesome-react-components) - A curated list of React components. |
|||
|
|||
- [Awesome React Talks](https://github.com/tiaanduplessis/awesome-react-talks) - A curated list of React talks. |
@ -0,0 +1,117 @@ |
|||
--- |
|||
id: meetups |
|||
title: Meetups Around the World |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/meetups.html |
|||
--- |
|||
|
|||
Do you have a local React.js meetup? Add it here! (Please keep the list alphabetical) |
|||
|
|||
## Australia |
|||
* [Melbourne](http://www.meetup.com/React-Melbourne/) |
|||
* [Sydney](http://www.meetup.com/React-Sydney/) |
|||
|
|||
## Austria |
|||
* [Vienna](http://www.meetup.com/Vienna-ReactJS-Meetup/) |
|||
|
|||
## Belgium |
|||
* [Belgium](http://www.meetup.com/ReactJS-Belgium/) |
|||
|
|||
## Brazil |
|||
* [Belo Horizonte](http://www.meetup.com/reactbh/) |
|||
* [Rio de Janeiro](https://www.meetup.com/pt-BR/React-Rio-de-Janeiro/) |
|||
* [São Paulo](http://www.meetup.com/pt-BR/ReactJS-SP/) |
|||
|
|||
## Canada |
|||
* [Vancouver, BC](http://www.meetup.com/ReactJS-Vancouver-Meetup/) |
|||
|
|||
## China |
|||
* [Beijing](http://www.meetup.com/Beijing-ReactJS-Meetup/) |
|||
|
|||
## Colombia |
|||
* [Medellin](https://www.meetup.com/React-Medellin/) |
|||
|
|||
## Denmark |
|||
* [Aalborg](https://www.meetup.com/Aalborg-React-React-Native-Meetup/) |
|||
* [Aarhus](https://www.meetup.com/Aarhus-ReactJS-Meetup/) |
|||
|
|||
## England (UK) |
|||
* [Manchester](http://www.meetup.com/Manchester-React-User-Group/) |
|||
|
|||
## France |
|||
* [Paris](http://www.meetup.com/ReactJS-Paris/) |
|||
|
|||
## Germany |
|||
* [Berlin](http://www.meetup.com/React-Berlin/) |
|||
* [Hamburg](http://www.meetup.com/Hamburg-React-js-Meetup/) |
|||
* [Munich](http://www.meetup.com/ReactJS-Meetup-Munich/) |
|||
|
|||
## Greece |
|||
* [Thessaloniki](https://www.meetup.com/Thessaloniki-ReactJS-Meetup/) |
|||
|
|||
## India |
|||
* [Bangalore](https://www.meetup.com/ReactJS-Bangalore/) |
|||
|
|||
## Ireland |
|||
* [Dublin](http://www.meetup.com/ReactJS-Dublin/) |
|||
|
|||
## Israel |
|||
* [Tel Aviv](http://www.meetup.com/ReactJS-Israel/) |
|||
|
|||
## Netherlands |
|||
* [Amsterdam](http://www.meetup.com/React-Amsterdam/) |
|||
|
|||
## New Zealand |
|||
* [Wellington](http://www.meetup.com/React-Wellington/) |
|||
|
|||
## Norway |
|||
* [Norway](http://reactjsnorway.com/) |
|||
* [Oslo](https://www.meetup.com/ReactJS-Oslo-Meetup/) |
|||
|
|||
## Peru |
|||
* [Lima](http://www.meetup.com/ReactJS-Peru/) |
|||
|
|||
## Philippines |
|||
* [Manila](http://www.meetup.com/reactjs-developers-manila/) |
|||
|
|||
## Poland |
|||
* [Warsaw](http://www.meetup.com/React-js-Warsaw/) |
|||
|
|||
## Spain |
|||
* [Barcelona](http://www.meetup.com/ReactJS-Barcelona/) |
|||
|
|||
## Sweden |
|||
* [Goteborg](http://www.meetup.com/ReactJS-Goteborg/) |
|||
|
|||
## Ukraine |
|||
* [Kyiv](https://www.meetup.com/Kyiv-ReactJS-Meetup) |
|||
|
|||
## US |
|||
* [Atlanta, GA - ReactJS](http://www.meetup.com/React-ATL/) |
|||
* [Austin, TX - ReactJS](http://www.meetup.com/ReactJS-Austin-Meetup/) |
|||
* [Boston, MA - ReactJS](http://www.meetup.com/ReactJS-Boston/) |
|||
* [Boston, MA - React Native](http://www.meetup.com/Boston-React-Native-Meetup/) |
|||
* [Chicago, IL - ReactJS](http://www.meetup.com/React-Chicago/) |
|||
* [Dallas, TX - ReactJS](http://www.meetup.com/ReactDallas/) |
|||
* [Irvine, CA - ReactJS](http://www.meetup.com/ReactJS-OC/) |
|||
* [Las Vegas, NV - ReactJS](http://www.meetup.com/ReactVegas/) |
|||
* [Leesburg, VA - ReactJS](http://www.meetup.com/React-NOVA/) |
|||
* [Los Angeles, CA - ReactJS](http://www.meetup.com/socal-react/) |
|||
* [Los Angeles, CA - React Native](http://www.meetup.com/React-Native-Los-Angeles/) |
|||
* [Nashville, TN - ReactJS](http://www.meetup.com/NashReact-Meetup/) |
|||
* [New York, NY - ReactJS](http://www.meetup.com/NYC-Javascript-React-Group/) |
|||
* [New York, NY - React Native](http://www.meetup.com/React-Native-NYC/) |
|||
* [Palo Alto, CA - React Native](http://www.meetup.com/React-Native-Silicon-Valley/) |
|||
* [Phoenix, AZ - ReactJS](http://www.meetup.com/ReactJS-Phoenix/) |
|||
* [Portland, OR - ReactJS](http://www.meetup.com/Portland-ReactJS/) |
|||
* [Provo, UT - ReactJS](http://www.meetup.com/ReactJS-Utah/) |
|||
* [Sacramento, CA - ReactJS](http://www.meetup.com/Sacramento-ReactJS-Meetup/) |
|||
* [San Francisco - ReactJS](http://www.meetup.com/ReactJS-San-Francisco/) |
|||
* [San Francisco, CA - React Native](http://www.meetup.com/React-Native-San-Francisco/) |
|||
* [Santa Monica, CA - ReactJS](http://www.meetup.com/Los-Angeles-ReactJS-User-Group/) |
|||
* [Seattle, WA - React Native](http://www.meetup.com/Seattle-React-Native-Meetup/) |
|||
* [Seattle, WA - ReactJS](http://www.meetup.com/seattle-react-js/) |
|||
* [Tampa, FL - ReactJS](http://www.meetup.com/ReactJS-Tampa-Bay/) |
|||
* [Tucson, AZ - ReactJS](http://www.meetup.com/Tucson-ReactJS-Meetup/) |
|||
* [Washington, DC - ReactJS](http://www.meetup.com/React-DC/) |
@ -1,14 +1,42 @@ |
|||
- title: Community Resources |
|||
items: |
|||
- id: support |
|||
title: Where To Get Support |
|||
title: Support |
|||
- id: conferences |
|||
title: Conferences |
|||
- id: meetups |
|||
title: Meetups |
|||
- id: articles |
|||
title: Articles |
|||
- id: podcasts |
|||
title: Podcasts |
|||
- id: videos |
|||
title: Videos |
|||
- id: courses |
|||
title: Courses |
|||
- id: examples |
|||
title: Examples |
|||
href: https://github.com/facebook/react/wiki/Examples |
|||
- id: complementary-tools |
|||
title: Complementary Tools |
|||
href: https://github.com/facebook/react/wiki/Complementary-Tools |
|||
- id: external-resources |
|||
title: External Resources |
|||
- title: Tools |
|||
items: |
|||
- id: debugging-tools |
|||
title: Debugging |
|||
- id: component-workbenches |
|||
title: Component Workbenches |
|||
- id: jsx-integrations |
|||
title: JSX Integrations |
|||
- id: starter-kits |
|||
title: Starter Kits |
|||
- id: routing |
|||
title: Routing |
|||
- id: model-management |
|||
title: Model Management |
|||
- id: data-fetching |
|||
title: Data Fetching |
|||
- id: testing |
|||
title: Testing |
|||
- id: ui-components |
|||
title: UI Components |
|||
- id: misc |
|||
title: Miscellaneous |
|||
|
@ -0,0 +1,24 @@ |
|||
--- |
|||
id: podcasts |
|||
title: Podcasts |
|||
layout: community |
|||
sectionid: community |
|||
permalink: community/podcasts.html |
|||
--- |
|||
|
|||
Podcasts dedicated to React and individual podcast episodes with React discussions. |
|||
|
|||
## Podcasts |
|||
|
|||
- [JavaScript Air](https://javascriptair.com/) - All about JavaScript (currently not producing new episodes). |
|||
|
|||
- [React 30](https://react30.com/) - A weekly 30-minute podcast all about React (currently not producing new episodes). |
|||
|
|||
- [React Podcast](https://itunes.apple.com/us/podcast/react-podcast/id995869265?mt=2) - A podcast covering the ReactJS ecosystem (currently not producing new episodes). |
|||
|
|||
## Episodes |
|||
|
|||
- [CodeWinds Episode 4](http://codewinds.com/podcast/004.html) - Pete Hunt talks with Jeff Barczewski about React. |
|||
|
|||
|
|||
- [JavaScript Jabber 73](https://devchat.tv/js-jabber/073-jsj-react-with-pete-hunt-and-jordan-walke) - Pete Hunt and Jordan Walke talk about React. |
@ -0,0 +1,13 @@ |
|||
--- |
|||
id: component-workbenches |
|||
title: Component Workbenches |
|||
layout: community |
|||
permalink: community/component-workbenches.html |
|||
--- |
|||
|
|||
* **[React Storybook](https://github.com/kadirahq/react-storybook):** UI component development environment for React. |
|||
* **[React Styleguidist](https://github.com/styleguidist/react-styleguidist):** Style guide generator & component workbench for React. |
|||
* **[React Showroom](https://github.com/OpusCapita/react-showroom-client):** React based components catalog which provides you with markdown documentation and live examples |
|||
* **[patternplate](https://github.com/sinnerschrader/patternplate)**: A platform for pattern and component library development using React. |
|||
* **[UiZoo.js](https://github.com/myheritage/UiZoo.js)**: Auto-generated component development environment by the JSDoc of React components. |
|||
* **[Neutrino React components preset](https://github.com/eliperelman/neutrino-preset-react-components/)**: Create generic React components and previewing them without the need to embed in an application. Plays nicely with other Neutrino middleware, so you can build, test, preview, and publish multiple React components from a single repository. |
@ -0,0 +1,12 @@ |
|||
--- |
|||
id: data-fetching |
|||
title: Data Fetching |
|||
layout: community |
|||
permalink: community/data-fetching.html |
|||
--- |
|||
|
|||
* **[Apollo](http://dev.apollodata.com/react/):** Easy to set up and use GraphQL client. |
|||
* **[Axios](https://github.com/mzabriskie/axios):** Promise based HTTP client for the browser and node.js. |
|||
* **[Relay Modern](https://facebook.github.io/relay/docs/relay-modern.html)** - A JavaScript framework for building data-driven React applications. |
|||
* **[Request](https://github.com/request/request):** Simplified HTTP request client. |
|||
* **[Superagent](https://visionmedia.github.io/superagent/):** A lightweight "isomorphic" library for AJAX requests. |
@ -0,0 +1,8 @@ |
|||
--- |
|||
id: debugging-tools |
|||
title: Debugging |
|||
layout: community |
|||
permalink: community/debugging-tools.html |
|||
--- |
|||
|
|||
* **[React Developer Tools](https://github.com/facebook/react-devtools):** an extension available for [Chrome](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi), [Firefox](https://addons.mozilla.org/firefox/addon/react-devtools/), and as a [standalone app](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) that allows you to inspect the React component hierarchy in the Chrome Developer Tools. |
@ -0,0 +1,53 @@ |
|||
--- |
|||
id: jsx-integrations |
|||
title: JSX Integrations |
|||
layout: community |
|||
permalink: community/jsx-integrations.html |
|||
--- |
|||
|
|||
## Editor Integrations |
|||
* **[Sublime Text: babel-sublime](https://github.com/babel/babel-sublime):** Snippets, syntax highlighting and optimized color schemes for Sublime Text |
|||
* **[Atom: language-babel](https://atom.io/packages/language-babel)** Support for es2016, JSX and Flow. |
|||
* **[Visual Studio Code](https://code.visualstudio.com/updates/vFebruary#_languages-javascript)** Visual Studio Code supports JSX directly. |
|||
* **[JetBrains WebStorm](http://www.jetbrains.com/webstorm/):** Syntax highlighting, code completion, error detection for JSX |
|||
* **[JetBrains IDE Live Templates](https://github.com/Minwe/jetbrains-react):** React live templates for JetBrains editors (e.g. WebStorm, PHPStorm, etc.) |
|||
* **[javascript-jsx.tmbundle](https://github.com/jjeising/javascript-jsx.tmbundle)** Syntax for TextMate |
|||
* **[web-mode.el](http://web-mode.org):** An autonomous emacs major mode that indents and highlights JSX. No support for Automatic Semicolon Insertion. |
|||
* **[vim-jsx](https://github.com/mxw/vim-jsx):** Syntax highlighting and indenting for JSX |
|||
|
|||
## Build Tools |
|||
|
|||
* **[Create React App](https://github.com/facebookincubator/create-react-app):** An **officially supported** way to create React apps with no configuration. |
|||
* **[nwb](https://github.com/insin/nwb)**: A toolkit for React, Preact & Inferno apps, React libraries and other npm modules for the web, with no configuration (until you need it) |
|||
* **[Neutrino](https://neutrino.js.org/)**: Create and build modern JavaScript applications with zero initial configuration. Neutrino combines the power of webpack with the simplicity of presets. |
|||
* **[ESLint](http://eslint.org):** A pluggable JavaScript linter that natively supports JSX syntax. Be sure to download [eslint-plugin-react](https://npmjs.com/package/eslint-plugin-react) for React-specific rules. |
|||
* **[Structor](https://www.npmjs.com/package/structor):** This tool is a user interface builder for node.js Web applications with React UI. Structor replaces the now deprecated React UI Builder. Watch [Structor Video Tutorials](https://youtu.be/z96xYa51EWI?list=PLAcaUOtEwjoR_U6eE2HQEXwkefeVESix1) |
|||
* **[react-jsx](https://github.com/bigpipe/react-jsx):** Compile and use JSX as stand-alone templates that can run server-side and client side! |
|||
* **[cjsx-codemod](https://github.com/jsdf/cjsx-codemod):** Write JSX code within Coffeescript! |
|||
* **[ReactScript](https://github.com/1j01/react-script):** Write React code within Coffeescript without JSX! |
|||
* **[jsxhint](https://npmjs.org/package/jsxhint):** [JSHint](http://jshint.com/) (linting) support. (JSX compilation doesn't affect line numbers so lint can also be run directly on the compiled JS.) |
|||
* **[reactify](https://npmjs.org/package/reactify):** [Browserify](http://browserify.org/) transform. |
|||
* **[Babel](https://babeljs.io/):** Standalone & [Browserify](http://browserify.org/) transform (formerly known as **6to5**). |
|||
* **[node-jsx](https://npmjs.org/package/node-jsx):** Native [Node](http://nodejs.org/) support. |
|||
* **[react-hot-loader](http://gaearon.github.io/react-hot-loader/):** Loader for [webpack](http://webpack.github.io/) that lets you edit JSX and have changes appear immediately in the browser without reloading the page. |
|||
* **[jsx-loader](https://npmjs.org/package/jsx-loader):** Loader for [webpack](http://webpack.github.io/). |
|||
* **[express-jsxtransform](https://www.npmjs.org/package/express-jsxtransform):** Middleware for [Express](https://www.npmjs.org/package/express). |
|||
* **[gradle-react-plugin](https://github.com/ehirsch/gradle-react-plugin):** Transform jsx sources during a gradle build. |
|||
* **[grunt-react](https://npmjs.org/package/grunt-react):** [GruntJS](http://gruntjs.com/) task. |
|||
* **[gulp-react](https://npmjs.org/package/gulp-react):** [GulpJS](http://gulpjs.com/) plugin. |
|||
* **[brunch-react](https://www.npmjs.org/package/react-brunch):** [Brunch](http://brunch.io/) plugin. |
|||
* **[jsx-requirejs-plugin](https://github.com/philix/jsx-requirejs-plugin):** [RequireJS](http://requirejs.org/) plugin. |
|||
* **[react-meteor](https://github.com/benjamn/react-meteor):** [Meteor](http://www.meteor.com/) plugin. |
|||
* **[pyReact](https://github.com/facebook/react-python):** [Python](http://www.python.org/) bridge to JSX. |
|||
* **[react-rails](https://github.com/facebook/react-rails):** Ruby gem for using JSX with [Ruby on Rails](http://rubyonrails.org/). |
|||
* **[react-laravel](https://github.com/talyssonoc/react-laravel):** PHP package for using ReactJS with [Laravel](http://laravel.com/). |
|||
* **[ReactJS.NET](http://reactjs.net/):** .NET library for React and JSX. |
|||
* **[sbt-reactjs](https://github.com/ddispaltro/sbt-reactjs)** SBT/Play/Scala JSX compiler plugin |
|||
* **[mimosa-react](https://github.com/dbashford/mimosa-react):** [Mimosa](http://mimosa.io) plugin. |
|||
* **[react-grails-asset-pipeline](https://github.com/peh/react-grails-asset-pipeline):** Assets for react and precompilation of jsx files in [Grails](http://grails.org/). |
|||
* **[gore-gulp](https://github.com/goreutils/gore-gulp):** Wrapper around [webpack](https://webpack.github.io/), [eslint](http://eslint.org/), [mocha](https://mochajs.org/) for ease of use and zero configuration. |
|||
* **[webpack](https://github.com/webpack/webpack):** Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff. |
|||
* **[webpack-bbq](https://github.com/wenbing/webpack-bbq):** transform your src to lib, supports server rendering and static rendering. |
|||
* **[jsxtransformer](https://github.com/cronn-de/jsxtransformer):** Compile pipeline for jsx files in Java |
|||
* **[babylon-jsx](https://github.com/marionebl/babylon-jsx)**: Transform JSX to ES2015 with babylon sans babel |
|||
* **[CRA Universal CLI](https://github.com/antonybudianto/cra-universal)** - A simple CLI to create and build Express server for your create-react-app projects, featuring Server-side rendering and Code-splitting. |
@ -0,0 +1,19 @@ |
|||
--- |
|||
id: misc |
|||
title: Miscellaneous |
|||
layout: community |
|||
permalink: community/misc.html |
|||
--- |
|||
|
|||
* **[react-localize-redux](https://github.com/ryandrewjohnson/react-localize-redux)** - Localization library for React/Redux. |
|||
|
|||
* **[react-inspector](https://github.com/xyc/react-inspector):** Use DevTools-like object inspectors inside your React app. |
|||
* **[jreact](https://github.com/KnisterPeter/jreact):** Rendering react server-side within a JVM (Java 7 or Java 8) |
|||
* **[react-jss](https://github.com/jsstyles/react-jss):** Inject and mount jss styles in React components. |
|||
* **[django-react](https://github.com/markfinger/django-react):** Server-side rendering of React components for django apps. |
|||
* **[react-engine](https://github.com/paypal/react-engine):** Composite render engine for isomorphic express apps to render both plain react views and react-router views. |
|||
* **[react-render-visualizer](https://github.com/redsunsoft/react-render-visualizer):** A visual way to see what is (re)rendering and why. |
|||
* **[javascript-monads](https://github.com/dschalk/javascript-monads):** As this project matures, the monads are becoming more than mere toys. React is used in unorthodox ways, so if you want to use React the way they do at Facebook, this is not for you. Transpiled code for the three monad classes can be downloaded by entering "npm install reactive-monads". |
|||
* **[ReactCSS](http://reactcss.com/):** Inline Styles in JS with support for React. |
|||
* **[ReactQuestionnaire](https://github.com/kouryuu/react-questionnaire):** Simple react components for building a questionnaire or survey. |
|||
* **[renderjs.io](http://renderjs.io):** SEO for Reactjs. Service for making reactjs application crawlable and shareable. |
@ -0,0 +1,20 @@ |
|||
--- |
|||
id: model-management |
|||
title: Model Management |
|||
layout: community |
|||
permalink: community/model-management.html |
|||
--- |
|||
|
|||
* **[Alt](http://alt.js.org/):** Pure vanilla flux made isomorphic and without the boilerplate. |
|||
* **[astarisx](http://zuudo.github.io/astarisx/):** Highly Composable MVVM Framework for React with built-in pushState router. |
|||
* **[avers](https://github.com/wereHamster/avers):** A modern client-side model abstraction library. |
|||
* **[backbone-react-component](https://github.com/magalhas/backbone-react-component):** Use multiple Backbone models and collections with React components both on the client and server sides. |
|||
* **[Baobab](https://github.com/Yomguithereal/baobab):** Persistent data tree supporting cursors. |
|||
* **[cortex](https://github.com/mquan/cortex/):** A JavaScript library for centrally managing data with React. |
|||
* **[DeLorean](https://github.com/deloreanjs/delorean):** A completely agnostic JavaScript framework to apply Flux concepts into your interfaces easily. |
|||
* **[Elsa](https://github.com/JonAbrams/elsa):** A Babel plugin that makes your arrays and objects immutable by default… and gives them super powers! |
|||
* **[Immutable](https://github.com/facebook/immutable-js):** Immutable data structures designed to be more JavaScript-y than Mori. |
|||
* **[js-data](http://www.js-data.io/):** A framework-agnostic frontend datastore, that will also fetch your data. |
|||
* **[McFly](https://github.com/kenwheeler/mcfly):** A lightweight Flux library that adds factories for Stores & Actions. |
|||
* **[NuclearJS](https://github.com/optimizely/nuclear-js):** Immutable, reactive Flux architecture. UI Agnostic. |
|||
* **[Reflux](https://github.com/spoike/refluxjs):** An event-based implementation of the Flux architecture that integrates with React components. |
@ -0,0 +1,16 @@ |
|||
--- |
|||
id: routing |
|||
title: Routing |
|||
layout: community |
|||
permalink: community/routing.html |
|||
--- |
|||
|
|||
* **[Aviator](https://github.com/swipely/aviator)** - Aviator is a front-end router built for modular single page applications. ([Example](https://gist.github.com/hojberg/9549330)). |
|||
* **[Backbone](http://backbonejs.org/)** - Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface. |
|||
* **[component-router](https://github.com/in-flux/component-router):** Flux-based routing solution for components |
|||
* **[Director](https://github.com/flatiron/director)** - A tiny and isomorphic URL router for JavaScript. |
|||
* **[Finch](http://stoodder.github.io/finchjs/)** - A simple, yet powerful, javascript route handling library. |
|||
* **[mvc-router](https://github.com/rajeev-k/mvc-router)** Use the Model-View-Controller (MVC) pattern to build React applications. |
|||
* **[react-mini-router](https://github.com/larrymyers/react-mini-router)** A minimal URL router mixin. |
|||
* **[react-router](https://github.com/rackt/react-router)** - A popular declarative router for React |
|||
* **[react-router-component](https://github.com/andreypopp/react-router-component)** Declarative routing. |
@ -0,0 +1,80 @@ |
|||
--- |
|||
id: starter-kits |
|||
title: Starter Kits |
|||
layout: community |
|||
permalink: community/starter-kits.html |
|||
--- |
|||
|
|||
## Client-side Kits |
|||
|
|||
* **[React CDK](https://github.com/kadirahq/react-cdk)** - Component Development Kit for React |
|||
* **[React Static Boilerplate](https://github.com/koistya/react-static-boilerplate):** Static site generator based on React.js, Gulp/Webpack, React Hot Loader, Babel, postCSS/cssnext. Best suited for deploying React.js site to GitHub Pages or Amazon S3. |
|||
* **[React Redux Boilerplate](https://github.com/iroy2000/react-redux-boilerplate):** React Redux Boilerplate is a workflow boilerplate that make life easier for developers by providing a virtual development environment and production ready build workflow out of the box. ( React, Redux, Reselect, Redux Actions, ES6, ESLint, Webpack with integrated environment config support ) |
|||
* **[React, TypeScript, JSPM starter-kit](https://github.com/piotrwitek/react-ts-jspm-starter-kit):** Unopinionated starter kit to build modular web apps with React & TypeScript powered by JSPM/SystemJS 0.17.X (ES2016, hot-reload, browser-sync, bundle for prod scripts) |
|||
* **[Subschema](https://subschema.github.io/subschema)** - Subschema is a Dependency Injection Library for React, included is a project starter, with webpack, karma and babel. |
|||
* **[React + Redux + Saga Boilerplate](https://github.com/gilbarbara/react-redux-saga-boilerplate)** - |
|||
Ready to grow boilerplate with react-router, redux, saga, webpack 2, jest w/ coverage and enzyme. |
|||
* **[generator-enigma](https://www.npmjs.com/package/generator-enigma)** a minimalist React application scaffolding tool that sets up a ready-to-deploy web app, complete with testing via Jest and optional `react-router` boilerplate. |
|||
* **[Component-Template](https://github.com/reactstrap/component-template)** - A create-react-app based starter kit for building, documenting, & publishing React Components. Includes React Router v4, Bootstrap 4 and Reactstrap. |
|||
|
|||
## Full-stack Kits |
|||
|
|||
* **[react-universally](https://github.com/ctrlplusb/react-universally)** A starter kit for universal react applications with React, Express, React Router (v4), ES2017, Flow, Jest, Service workers, Data-fetching and code-splitting. |
|||
* **[web-service-template](https://github.com/nandai/web-service-template)** Membership single-page application with React and TypeScript. |
|||
* **[starter-react-flux](https://github.com/SokichiFujita/starter-react-flux)** A generator for React and Flux project with Flux-Utils, Jest, Immutable.js, React Addons, Webpack, ESLint, Babel and ES2015. |
|||
* **[react-slingshot](https://github.com/coryhouse/react-slingshot):** React + Redux starter kit with Babel, hot reloading, testing, linting and a working example app. |
|||
* **[react-async-starter](https://github.com/didierfranc/react-async-starter):** React + Redux + Fetch + ES7 Async with Webpack, Babel and hot reloading. |
|||
* **[spa-starter-kit](https://github.com/vutran/spa-starter-kit):** Full stack Docker node.js container with React, webpack, babel, sass, ESLint, React Hot Loader, Redux for a single-page application. |
|||
* **[react-flux-starter-kit](https://github.com/coryhouse/react-flux-starter-kit):** React, Flux, React Router with Browserify, Bootstrap, and ESLint, all wired up via Gulp. Includes link to associated course. |
|||
* **[exnext-quickstart](https://github.com/nkbt/esnext-quickstart):** Compilation, testing, code validation (ESLint) and hot reloading |
|||
* **[react-component-template](https://github.com/nkbt/react-component-template):** Base for npm-publisheable standalone React Components with tests, ES6 coverage |
|||
* **[Base](https://github.com/adeperio/base):** An open-source, security focused, web application starter kit. |
|||
Built with ReactJS, Flux, Express, and Postgres. |
|||
* **[Este](https://github.com/este/este):** Dev stack and starter kit for functional and universal (browser, server, mobile) React applications. Everything you need to start is included. |
|||
* **[essential-react](https://github.com/pheuter/essential-react):** A minimal skeleton for building testable React apps using ES6 |
|||
* **[jspm-react](https://github.com/capaj/jspm-react):** Lightweight boilerplate on JSPM/Systemjs with hot-reloading modules for the browser |
|||
* **[react-flux-coffeescript-browserify-gulp-demo](https://github.com/dqdinh/react-flux-coffeescript-browserify-gulp-demo):** React, Flux, Coffeescript, Browserify, Watchify, Gulp |
|||
* **[react-reflux-boilerplate-with-webpack](https://github.com/iroy2000/react-reflux-boilerplate-with-webpack):** React Reflux Workflow Boilerplate -- React, Reflux, Gulp, Webpack, Stylus and CoffeeScript. |
|||
* **[kontraktor-intrinsic-jsx](https://github.com/RuedigerMoeller/InstrinsicReactJSX):** Native Java-implementation of JSX Transpiler + Bundler + Server (no nashorn or node/babel required) |
|||
* **[React-Phonegap App](https://github.com/kjda/ReactJs-Phonegap):** Phonegap App built with react using Flux. |
|||
* **[Kriasoft React Starter Kit](https://github.com/kriasoft/react-starter-kit):** Gulp, Webpack, BrowserSync + [React Starter Kit for Visual Studio](http://visualstudiogallery.msdn.microsoft.com/d65d6b29-6dd7-4100-81b1-609e5afce356) |
|||
* **[react-express-template](https://github.com/khaled/react-express-template):** Web app starter template with React, React Router, ES6 (via Babel), CoffeeScript, Express/Node.js, Semantic-UI, Gulp, LiveReload, and more |
|||
* **[generator-react-webpack](https://github.com/newtriks/generator-react-webpack):** [Yeoman](http://yeoman.io/) generator for React and Webpack. |
|||
* **[generator-react-express](https://github.com/JedWatson/generator-react-express):** [Yeoman](http://yeoman.io/) generator for React and Express with browserify, react-router and bootstrap. |
|||
* **[generator-react-component](https://github.com/JedWatson/generator-react-component):** [Yeoman](http://yeoman.io/) generator React Component projects with Gulp, Browserify, Live Reload and publishing to GitHub Pages. |
|||
* **[Racket](https://github.com/mohebifar/racket):** [Yeoman](http://yeoman.io/) generator for creating a universal React Redux web application. |
|||
* **[Genesis Skeleton](http://genesis-skeleton.com/):** Modern, opinionated, full-stack starter kit for rapid, streamlined application development (supports React). |
|||
* **[react-starter-template](https://github.com/johnthethird/react-starter-template):** Starter template with Gulp, Webpack and Bootstrap. |
|||
* **[react-brunch](https://npmjs.org/package/react-brunch):** [Brunch](http://brunch.io/) plugin. |
|||
* **[react-browserify-template](https://github.com/petehunt/react-browserify-template):** Quick-start with Browserify. |
|||
* **[react-router-bootstrap-seed](https://github.com/okigan/react-router-bootstrap-seed):** Starter template with react-router, react-bootstrap and react-bootstrap-router (build with Gulp). |
|||
* **[React Phonegap Starter](https://github.com/stample/gulp-browserify-react-phonegap-starter)**: |
|||
Gulp, NPM, Browserify, React, Phonegap, Less, Recess, Underscore, JQuery... |
|||
* **[generator-react-gulp-browserify](https://github.com/randylien/generator-react-gulp-browserify)** [Yeoman](http://yeoman.io/) generator for React, Gulp, Browserify and Twitter Bootstrap Sass official. |
|||
* **[generator-react-boilerplate](https://github.com/mitchbox/generator-react-boilerplate)** [Yeoman](http://yeoman.io/) generator for React, Gulp, Browserify, Bootstrap and Fluxxor. |
|||
* **[react-starterify](https://github.com/Granze/react-starterify):** React JS application skeleton using Browserify and other awesome tools |
|||
* **[fluxury](https://github.com/jim-y/fluxury):** A React/Flux starter kit with NPM (build tool), Browserify, ImmutableJS, JSXHint and React-Router completely written in ES6 (Babelify transform). |
|||
* **[react-app-boilerplate](https://github.com/christianalfoni/react-app-boilerplate):** Browserify workflow with automatic JSX transformation, dependency handling for fast builds and jasmine test environment. |
|||
* **[nuts](https://github.com/micahlmartin/nuts):** A fully-featured starter kit that uses webpack, react, flux, backbone, mongo, and kue. Includes server-side and client-side rendering. |
|||
* **[generator-rc](https://github.com/react-component/generator-rc):** A scaffold to develop react component quickly. |
|||
* **[MimosaReactBackbone](https://github.com/dbashford/MimosaReactBackboneTodoList):** A TodoMVC React/Backbone app w/ Mimosa for tooling. |
|||
* **[TodoMVC - NestedReact](https://github.com/gaperton/todomvc-nestedreact):** TodoMVC React app built with [NestedTypes](https://github.com/Volicon/NestedTypes) and [NestedReact](https://github.com/Volicon/NestedReact). |
|||
* **[react-boilerplate](https://github.com/AbeEstrada/react-boilerplate):** It is a basic React project boilerplate, it uses JSX, React Router, Browserify, Reactify (ES6) and SASS. |
|||
* **[koa-react-full-example](https://github.com/dozoisch/koa-react-full-example)** Boilerplate of a Koa React integration. Also shows a way to integrate koa-passport, react-router and react-bootstrap and a few other common modules. Includes an authentication flow. |
|||
* **[generator-simple-react-browserify](https://github.com/luisrudge/generator-simple-react-browserify)** Really simple React + Browserify app generator for yeoman. Start here if you're trying to actually learn something. |
|||
* **[react-starterkit-with-reflux](https://github.com/maisnamraju/react-starterkit)** It's a fork of [react-starterkit](https://github.com/wbkd/react-starterkit) with React, Reflux, ES6 with Babel, Fontawesome, SASS, Bootstrap SASS(not react-bootstrap), and Browserify. |
|||
* **[react-jspm](https://github.com/chenxsan/react-jspm)** Boilerplate for developing React with jspm and SystemJS module loader. |
|||
* **[electron-react-boilerplate](https://github.com/chentsulin/electron-react-boilerplate)** A React + Flux Electron application boilerplate based on React, Flux, React Router, Webpack, React Hot Loader |
|||
* **[Coils](https://github.com/zubairq/coils):** React/SQL full stack realtime framework in Clojure |
|||
* **[isomorphic-flux-react-react-router](https://github.com/jahrlin/isomorphic-flux-react-react-router):** A clean, unbloated starter template without any unnecessary complexity for isomorphic web apps using React, Flux, react-router. Uses gulp and webpack for builds, jest for testing and SASS for CSS preprocessing. |
|||
* **[generator-sui-react](https://github.com/SUI-Components/generator-sui-react):** A [Yeoman](http://yeoman.io/) generator for Schibsted User Interface (sui) ReactJS components. The generator provides a basic structure to start developing a component, including coding standard rules, naming conventions and a unit testing suite. |
|||
* **[Universal-routed-flux-demo](https://github.com/pierreavizou/universal-routed-flux-demo)** Example app to get started building universal flux applications, with Reactjs, React Router and es6. |
|||
* **[react-starter](https://github.com/aliakakis/react-starter/)** React starter project with ES2015, Browserify, Babel, mobservable. |
|||
* **[react-flux-flow-webpack-jest-es6](https://github.com/msalia/react-flux-flow-webpack-jest-es6)** A complete React, Flux, Flow, Webpack, Jest and ES6 starter kit. |
|||
* **[react-boilerplate](https://github.com/mxstbr/react-boilerplate)** Quick setup for performance orientated, offline-first React.js applications featuring Redux, hot-reloading, PostCSS, react-router, ServiceWorker, AppCache, FontFaceObserver and Mocha. |
|||
* **[vortigern](https://github.com/barbar/vortigern)** A universal boilerplate for building web applications w/ TypeScript, React, Redux and more. |
|||
* **[react-redux-starter-kit](https://github.com/davezuko/react-redux-starter-kit):** Terrific universal Redux + React Router starter kit with Babel, SASS, hot reloading, testing, linting. Unopinionated as possible. |
|||
* **[prax](https://github.com/mitranim/prax):** Sane functional programming style architecture for realtime apps, with single immutable state, event system, reactive views, support development through pure functions. |
|||
* **[react-redux-universal-boilerplate](https://github.com/kiki-le-singe/react-redux-universal-boilerplate):** |
|||
An Universal ReactJS/Redux Boilerplate with Babel, Webpack 2, Webpack backend bundling, React Hot Loader 3, sass or cssnext, testing, linting... |
|||
* **[FUJITSU K5 Playground](https://playground.cloud.global.fujitsu.com)** A SPA and BFF generator with React, Flux, Swagger, Node.js, Material-ui, Jest, Webpack, ESLint and Babel. |
@ -0,0 +1,13 @@ |
|||
--- |
|||
id: testing |
|||
title: Testing |
|||
layout: community |
|||
permalink: community/testing.html |
|||
--- |
|||
|
|||
* **[Enzyme](https://github.com/airbnb/enzyme/):** a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output. |
|||
* **[Expect-jsx](https://github.com/algolia/expect-jsx):** toEqualJSX for [expect.js](https://github.com/mjackson/expect) |
|||
* **[Jest](https://facebook.github.io/jest/):** Delightful JavaScript testing used by Facebook to test all JavaScript code including React applications. |
|||
* **[React-unit](https://github.com/pzavolinsky/react-unit):** a lightweight unit test library for ReactJS with very few (js-only) dependencies. |
|||
* **[Skin-deep](https://github.com/glenjamin/skin-deep):** Testing helpers for use with React's shallowRender test utils. |
|||
* **[Unexpected-react](https://github.com/bruderstein/unexpected-react/):** Plugin for the [unexpected](http://unexpected.js.org) assertion library that makes it easy to assert over your React Components and trigger events. |
@ -0,0 +1,76 @@ |
|||
--- |
|||
id: ui-components |
|||
title: UI Componets |
|||
layout: community |
|||
permalink: community/ui-components.html |
|||
--- |
|||
|
|||
## Free Components |
|||
* **[Amaze UI React](https://github.com/amazeui/amazeui-react) (in Chinese):** [Amaze UI](https://github.com/allmobilize/amazeui) components built with React. |
|||
* **[Ant Design of React](http://github.com/ant-design/ant-design)** An enterprise-class UI design language and React-based implementation. |
|||
* **[Belle](https://github.com/nikgraf/belle/):** Configurable React Components with great UX. |
|||
* **[chartify](https://github.com/kirillstepkin/chartify)**: Ultra lightweight and customizable React.js chart component. |
|||
* **[Elemental UI](http://elemental-ui.com):** A UI toolkit for React websites and apps, themeable and composed of individually packaged components |
|||
* **[Grommet](http://grommet.io)** The most advanced open source UX framework for enterprise applications. |
|||
* **[Halogen](http://madscript.com/halogen):** A collection of highly customizable loading spinner animations with React. |
|||
* **[Khan Academy's component library](http://khan.github.io/react-components/)** |
|||
* **[markdown-to-jsx](https://www.npmjs.com/package/markdown-to-jsx)**: compiles markdown into safe React JSX without using dangerous escape hatches. |
|||
* **[material-ui](http://material-ui.com)** A set of React Components that implement Google's Material Design. |
|||
* **[Onsen UI React Components](https://onsen.io/v2/react.html):** UI components for hybrid mobile apps with both Material Design for Android and flat design for iOS. |
|||
* **[React Amazing Grid](https://github.com/Amazing-Space-Invader/react-amazing-grid)** Flex grid with inline styles. |
|||
* **[React Mdl](https://github.com/tleunen/react-mdl)** React Components for Material Design Lite. |
|||
* **[React Web](https://github.com/taobaofed/react-web)** A framework for building web apps with React. |
|||
* **[react-amiga-guru-meditation](https://github.com/gfazioli/react-amiga-guru-meditation):** React JS Class to display a Amiga Guru Meditation Tribute |
|||
* **[react-autosuggest](https://github.com/moroshko/react-autosuggest)** WAI-ARIA compliant React autosuggest component |
|||
* **[react-bootstrap](https://github.com/stevoland/react-bootstrap):** Bootstrap 3 components built with React. |
|||
* **[react-bootstrap-dialog](https://github.com/akiroom/react-bootstrap-dialog):** React Dialog component for react-bootstrap, instead of `window.alert` or `window.confirm` |
|||
* **[react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-table):** It's a react table for Bootstrap. |
|||
* **[react-component](https://github.com/react-component/):** A collection of react components maintained by Alibaba/Alipay employee. |
|||
* **[react-data-menu](https://github.com/dkozar/react-data-menu):** Smart data-driven menu rendered in an overlay. Hints-based aligning with custom renderers and factories. Never clipped by other components or screen edges. |
|||
* **[react-date-picker](https://github.com/Hacker0x01/react-datepicker):** A simple and reusable datepicker component for React. |
|||
* **[react-dates](https://github.com/OpusCapita/react-dates):** Date-inputs + date-picker |
|||
* **[react-dnd](https://github.com/gaearon/react-dnd)** Flexible HTML5 drag-and-drop mixin for React with full DOM control |
|||
* **[react-document-title](https://github.com/gaearon/react-document-title)** Declarative, nested, stateful, isomorphic document.title for React |
|||
* **[react-dropzone](https://github.com/felixrieseberg/React-Dropzone):** React Dropzone for File-Uploads |
|||
* **[react-forms](http://prometheusresearch.github.io/react-forms/):** Form rendering and validation for React |
|||
* |
|||
* **[react-highlight](https://github.com/akiran/react-highlight):** React component for syntax highlighting |
|||
* **[react-image](https://github.com/yuanyan/react-image):** Like `<img />` and Enhanced Image Component for React. |
|||
* **[react-input-autosize](https://github.com/JedWatson/react-input-autosize):** Like `<input />` but resizes automatically to fit all its content. |
|||
* **[react-intense](https://github.com/brycedorn/react-intense):** A component for viewing large images up close |
|||
* **[react-joyride](https://github.com/gilbarbara/react-joyride):** Create walkthroughs and guided tours for your ReactJS apps. |
|||
* **[react-ladda](https://github.com/jsdir/react-ladda):** React wrapper for Ladda buttons. |
|||
* **[react-lorem-component](https://github.com/martinandert/react-lorem-component):** Lorem Ipsum placeholder component. |
|||
* **[react-notification](https://github.com/pburtchaell/react-notification):** Snackbar style notifications |
|||
* |
|||
* **[react-select](https://github.com/JedWatson/react-select):** Native React Select / Multiselect input field, similar to Selectize / Chosen / Select2 |
|||
* **[react-selectize](https://furqanzafar.github.io/react-selectize/):** A stateless & flexible Select component, designed as a drop in replacement for React.DOM.Select, inspired by Selectize |
|||
* **[react-sigma](https://www.npmjs.com/package/react-sigma)**: Lightweight but powerful library for drawing network graphs |
|||
* **[react-slick](https://github.com/akiran/react-slick):** Carousel component built with React |
|||
* **[react-sparklines](https://borisyankov.github.io/react-sparklines/):** Beautiful and expressive sparklines component |
|||
* **[react-spreadsheet](https://github.com/felixrieseberg/React-Spreadsheet-Component):** React Spreadsheets / Editable tables with Excel-Style keyboard input and navigation |
|||
* **[react-switch-button](https://github.com/gfazioli/react-switch-button):** Beautiful React Switch button component |
|||
* **[react-tappable](https://github.com/JedWatson/react-tappable)** A Tappable React Component that provides native-feeling onTap events for mobile React apps |
|||
* **[react-textarea-autosize](https://github.com/andreypopp/react-textarea-autosize):** Like `<textarea />` but resizes automatically to fit all its content. |
|||
* **[React-TimeAgo](https://www.npmjs.org/package/react-timeago)** A minimal live updating Time Ago component that smartly converts any time to a 'ago' or 'from now' format and keeps it updated. |
|||
* **[react-translate-component](https://github.com/martinandert/react-translate-component):** React component for i18n. |
|||
* **[react-treeview](https://github.com/chenglou/react-treeview):** Easy, light, flexible tree view. |
|||
* **[react-uwp](https://www.react-uwp.com)** A set of React Components that Implement Microsoft's UWP Design & Fluent Design.. |
|||
* **[react-validate-framework](https://github.com/MinJieLiu/react-validate-framework)**: A lightweight and extensible React validation component. |
|||
* **[reactstrap](https://reactstrap.github.io/):** Simple Bootstrap 4 components built with [tether](http://tether.io/) |
|||
* **[recharts](https://github.com/recharts/recharts)**: A composable charting library built on React components. |
|||
* **[Selectivity](https://arendjr.github.io/selectivity/):** Modular and light-weight selection library. |
|||
* **[Semantic-ui](http://react.semantic-ui.com/)**: The official Semantic-UI-React integration, Advanced components and declarative UI. |
|||
* **[storybook-addon-material-ui](https://github.com/sm-react/storybook-addon-material-ui)** A storybook addon for material-ui. |
|||
* **[tcomb-form](https://github.com/gcanti/tcomb-form):** Automatically generate form markup, automatic labels and inline validation from a domain model. |
|||
* **[valuelink](https://github.com/Volicon/valuelink):** Full-featured two-way data binding and forms validation with extended React links. |
|||
* **[video-react](https://github.com/video-react/video-react)**: A web video player built for the HTML5 world using React library. |
|||
* **[Winterfell](https://github.com/andrewhathaway/Winterfell):** Generate complex, validated and extendable JSON-based forms in React |
|||
|
|||
## Fee Based Components |
|||
|
|||
* **[ag-Grid](https://www.ag-grid.com)** Advanced data grid / data table for React. |
|||
* **[ExtReact components](https://www.sencha.com/products/extreact//)**: 115+ Ready-to-Use UI Components. |
|||
* **[Grapecity Wijmo UI Components for React](https://www.grapecity.com/en/react/)**: Expand your React UI options with Wijmo’s complete collection of JavaScript components. |
|||
* **[jQWidgets React components](http://www.jqwidgets.com/react/)**: Enterprise Ready 70+ UI Components. |
|||
* **[Mobiscroll React UI Components](https://mobiscroll.com/react)** Mobile UI Controls for the Productive React Developer. |
@ -0,0 +1,88 @@ |
|||
--- |
|||
id: faq-ajax |
|||
title: AJAX and APIs |
|||
permalink: docs/faq-ajax.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### How can I make an AJAX call? |
|||
|
|||
You can use any AJAX library you like with React. Some popular ones are [Axios](https://github.com/axios/axios), [jQuery AJAX](https://api.jquery.com/jQuery.ajax/), and the browser built-in [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). |
|||
|
|||
### Where in the component lifecycle should I make an AJAX call? |
|||
|
|||
You should populate data with AJAX calls in the [`componentDidMount`](/docs/react-component.html#mounting) lifecycle method. This is so you can use `setState` to update your component when the data is retrieved. |
|||
|
|||
### Example: Using AJAX results to set local state |
|||
|
|||
The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state. |
|||
|
|||
The example API returns a JSON object like this: |
|||
|
|||
``` |
|||
{ |
|||
items: [ |
|||
{ id: 1, name: 'Apples', price: '$2' }, |
|||
{ id: 2, name: 'Peaches', price: '$5' } |
|||
] |
|||
} |
|||
``` |
|||
|
|||
```jsx |
|||
class MyComponent extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.state = { |
|||
error: null, |
|||
isLoaded: false, |
|||
items: [] |
|||
}; |
|||
} |
|||
|
|||
componentDidMount() { |
|||
fetch("https://api.example.com/items") |
|||
.then(res => res.json()) |
|||
.then( |
|||
(result) => { |
|||
this.setState({ |
|||
isLoaded: true, |
|||
items: result.items |
|||
}); |
|||
}, |
|||
// Note: it's important to handle errors here |
|||
// instead of a catch() block so that we don't swallow |
|||
// exceptions from actual bugs in components. |
|||
(error) => { |
|||
this.setState({ |
|||
isLoaded: true, |
|||
error |
|||
}); |
|||
} |
|||
) |
|||
} |
|||
|
|||
render() { |
|||
const { error, isLoaded, items } = this.state; |
|||
if (error) { |
|||
return <div>Error: {error.message}</div>; |
|||
} else if (!isLoaded) { |
|||
return <div>Loading...</div>; |
|||
} else { |
|||
return ( |
|||
<ul> |
|||
{items.map(item => ( |
|||
<li key={item.name}> |
|||
{item.name} {item.price} |
|||
</li> |
|||
))} |
|||
</ul> |
|||
); |
|||
} |
|||
} |
|||
} |
|||
``` |
|||
|
|||
### Cancellation |
|||
|
|||
Note that if the component unmounts before an AJAX call is complete, you may see a warning like `cannot read property 'setState' of undefined`. If this is an issue you may want to keep track of inflight AJAX requests and cancel them in the `componentWillUnmount` lifecycle method. |
@ -0,0 +1,24 @@ |
|||
--- |
|||
id: faq-build |
|||
title: Babel, JSX, and Build Steps |
|||
permalink: docs/faq-build.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### Do I need to use JSX with React? |
|||
|
|||
No! Check out ["React Without JSX"](/docs/react-without-jsx.html) to learn more. |
|||
|
|||
### Do I need to use ES6 (+) with React? |
|||
|
|||
No! Check out ["React Without ES6"](/docs/react-without-es6.html) to learn more. |
|||
|
|||
### How can I write comments in JSX? |
|||
|
|||
```jsx |
|||
<div> |
|||
{/* Comment goes here */} |
|||
Hello, {name}! |
|||
</div> |
|||
``` |
@ -0,0 +1,297 @@ |
|||
--- |
|||
id: faq-functions |
|||
title: Passing Functions to Components |
|||
permalink: docs/faq-functions.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### How do I pass an event handler (like onClick) to a component? |
|||
|
|||
Pass event handlers and other functions as props to child components: |
|||
|
|||
```jsx |
|||
<button onClick={this.handleClick}> |
|||
``` |
|||
|
|||
If you need to have access to the parent component in the handler, you also need to bind the function to the component instance (see below). |
|||
|
|||
### How do I bind a function to a component instance? |
|||
|
|||
There are several ways to make sure functions have access to component attributes like `this.props` and `this.state`, depending on which syntax and build steps you are using. |
|||
|
|||
#### Bind in Constructor (ES2015) |
|||
|
|||
```jsx |
|||
class Foo extends Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleClick = this.handleClick.bind(this); |
|||
} |
|||
handleClick() { |
|||
console.log('Click happened'); |
|||
} |
|||
render() { |
|||
return <button onClick={this.handleClick}>Click Me</button>; |
|||
} |
|||
} |
|||
``` |
|||
|
|||
#### Class Properties (Stage 3 Proposal) |
|||
|
|||
```jsx |
|||
class Foo extends Component { |
|||
// Note: this syntax is experimental and not standardized yet. |
|||
handleClick = () => { |
|||
console.log('Click happened'); |
|||
} |
|||
render() { |
|||
return <button onClick={this.handleClick}>Click Me</button>; |
|||
} |
|||
} |
|||
``` |
|||
|
|||
#### Bind in Render |
|||
|
|||
```jsx |
|||
class Foo extends Component { |
|||
handleClick() { |
|||
console.log('Click happened'); |
|||
} |
|||
render() { |
|||
return <button onClick={this.handleClick.bind(this)}>Click Me</button>; |
|||
} |
|||
} |
|||
``` |
|||
|
|||
>**Note:** |
|||
> |
|||
>Using `Function.prototype.bind` in render creates a new function each time the component renders, which may have performance implications (see below). |
|||
|
|||
#### Arrow Function in Render |
|||
|
|||
```jsx |
|||
class Foo extends Component { |
|||
handleClick() { |
|||
console.log('Click happened'); |
|||
} |
|||
render() { |
|||
return <button onClick={() => this.handleClick()}>Click Me</button>; |
|||
} |
|||
} |
|||
``` |
|||
|
|||
>**Note:** |
|||
> |
|||
>Using an arrow function in render creates a new function each time the component renders, which may have performance implications (see below). |
|||
|
|||
### Is it OK to use arrow functions in render methods? |
|||
|
|||
Generally speaking, yes, it is OK, and it is often the easiest way to pass parameters to callback functions. |
|||
|
|||
If you do have performance issues, by all means, optimize! |
|||
|
|||
### Why is binding necessary at all? |
|||
|
|||
In JavaScript, these two code snippets are **not** equivalent: |
|||
|
|||
```js |
|||
obj.method(); |
|||
``` |
|||
|
|||
```js |
|||
var method = obj.method; |
|||
method(); |
|||
``` |
|||
|
|||
Binding methods helps ensure that the second snippet works the same way as the first one. |
|||
|
|||
With React, typically you only need to bind the methods you *pass* to other components. For example, `<button onClick={this.handleClick}>` passes `this.handleClick` so you want to bind it. However, it is unnecessary to bind the `render` method or the lifecycle methods: we don't pass them to other components. |
|||
|
|||
[This post by Yehuda Katz](http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/) explains what binding is, and how functions work in JavaScript, in detail. |
|||
|
|||
### Why is my function being called every time the component renders? |
|||
|
|||
Make sure you aren't _calling the function_ when you pass it to the component: |
|||
|
|||
```jsx |
|||
render() { |
|||
// Wrong: handleClick is called instead of passed as a reference! |
|||
return <button onClick={this.handleClick()}>Click Me</button> |
|||
} |
|||
``` |
|||
|
|||
Instead, *pass the function itself* (without parens): |
|||
|
|||
```jsx |
|||
render() { |
|||
// Correct: handleClick is passed as a reference! |
|||
return <button onClick={this.handleClick}>Click Me</button> |
|||
} |
|||
``` |
|||
|
|||
### How do I pass a parameter to an event handler or callback? |
|||
|
|||
You can use an arrow function to wrap around an event handler and pass parameters: |
|||
|
|||
```jsx |
|||
<button onClick={() => this.handleClick(id)} /> |
|||
``` |
|||
|
|||
This is equivalent to calling `.bind`: |
|||
|
|||
```jsx |
|||
<button onClick={this.handleClick.bind(this, id)} /> |
|||
``` |
|||
|
|||
#### Example: Passing params using arrow functions |
|||
|
|||
```jsx |
|||
const A = 65 // ASCII character code |
|||
|
|||
class Alphabet extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleClick = this.handleClick.bind(this); |
|||
this.state = { |
|||
justClicked: null, |
|||
letters: Array.from({length: 26}, (_, i) => String.fromCharCode(A + i)). |
|||
}; |
|||
} |
|||
handleClick(letter) { |
|||
this.setState({ justClicked: letter }); |
|||
} |
|||
render() { |
|||
return ( |
|||
<div> |
|||
Just clicked: {this.state.justClicked} |
|||
<ul> |
|||
{this.state.letters.map(letter => |
|||
<li key={letter} onClick={() => this.handleClick(letter)}> |
|||
{letter} |
|||
</li> |
|||
)} |
|||
</ul> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
``` |
|||
|
|||
#### Example: Passing params using data-attributes |
|||
|
|||
Alternately, you can use DOM APIs to store data needed for event handlers. Consider this approach if you need to optimize a large number of elements or have a render tree that relies on React.PureComponent equality checks. |
|||
|
|||
```jsx |
|||
const A = 65 // ASCII character code |
|||
|
|||
class Alphabet extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleClick = this.handleClick.bind(this); |
|||
this.state = { |
|||
justClicked: null, |
|||
letters: Array.from({length: 26}, (_, i) => String.fromCharCode(A + i)) |
|||
}; |
|||
} |
|||
|
|||
handleClick(e) { |
|||
this.setState({ |
|||
justClicked: e.target.dataset.letter |
|||
}); |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<div> |
|||
Just clicked: {this.state.justClicked} |
|||
<ul> |
|||
{this.state.letters.map(letter => |
|||
<li key={letter} data-letter={letter} onClick={this.handleClick}> |
|||
{letter} |
|||
</li> |
|||
)} |
|||
</ul> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
``` |
|||
|
|||
### How can I prevent a function from being called too quickly or too many times in a row? |
|||
|
|||
If you have an event handler such as `onClick` or `onScroll` and want to prevent the callback from being fired too quickly, you can wrap the handler with a utility such as [`_.debounce`](https://lodash.com/docs#debounce) or [`_.throttle`](https://lodash.com/docs#throttle). See [this visualization](http://demo.nimius.net/debounce_throttle/) for a comparison of the two. |
|||
|
|||
> Note: |
|||
> |
|||
> Both `_.debounce` and `_.throttle` provide a `cancel` method to cancel delayed callbacks. You should either call this method from `componentWillUnmount` _or_ check to ensure that the component is still mounted within the delayed function. |
|||
|
|||
#### Throttle |
|||
|
|||
Throttling prevents a function from being called more than once in a given window of time. The example below throttles a "click" handler to prevent calling it more than once per second. |
|||
|
|||
```jsx |
|||
import throttle from 'lodash.throttle'; |
|||
|
|||
class LoadMoreButton extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleClick = this.handleClick.bind(this); |
|||
this.handleClickThrottled = throttle(this.handleClick, 1000); |
|||
} |
|||
|
|||
componentWillUnmount() { |
|||
this.handleClickThrottled.cancel(); |
|||
} |
|||
|
|||
render() { |
|||
return <button onClick={this.handleClickThrottled}>Load More</button>; |
|||
} |
|||
|
|||
handleClick() { |
|||
this.props.loadMore(); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
#### Debounce |
|||
|
|||
Debouncing ensures that a function will not be executed until after a certain amount of time has passed since it was last called. This can be useful when you have to perform some expensive calculation in response to an event that might dispatch rapidly (eg scroll or keyboard events). The example below debounces text input with a 250ms delay. |
|||
|
|||
```jsx |
|||
import debounce from 'lodash.debounce'; |
|||
|
|||
class Searchbox extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleChange = this.handleChange.bind(this); |
|||
this.emitChangeDebounced = debounce(this.emitChange, 250); |
|||
} |
|||
|
|||
componentWillUnmount() { |
|||
this.emitChangeDebounced.cancel(); |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<input |
|||
type="text" |
|||
onChange={this.handleChange} |
|||
placeholder="Search..." |
|||
defaultValue={this.props.value} |
|||
/> |
|||
); |
|||
} |
|||
|
|||
handleChange(e) { |
|||
// React pools events, so we read the value before debounce. |
|||
// Alternately we could call `event.persist()` and pass the entire event. |
|||
// For more info see reactjs.org/docs/events.html#event-pooling |
|||
this.emitChangeDebounced(e.target.value); |
|||
} |
|||
|
|||
emitChange(value) { |
|||
this.props.onChange(value); |
|||
} |
|||
} |
|||
``` |
@ -0,0 +1,23 @@ |
|||
--- |
|||
id: faq-internals |
|||
title: Virtual DOM and Internals |
|||
permalink: docs/faq-internals.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### What is the Virtual DOM? |
|||
|
|||
The virtual DOM (VDOM) is a programming concept where an ideal, or "virtual", representation of a UI is kept in memory and synced with the "real" DOM by a library such as ReactDOM. This process is called [reconciliation](/docs/reconciliation.html). |
|||
|
|||
This approach enables the declarative API of React: You tell React what state you want the UI to be in, and it makes sure the DOM matches that state. This abstracts out the attribute manipulation, event handling, and manual DOM updating that you would otherwise have to use to build your app. |
|||
|
|||
Since "virtual DOM" is more of a pattern than a specific technology, people sometimes say it to mean different things. In React world, the term "virtual DOM" is usually associated with [React elements](/docs/rendering-elements.html) since they are the objects representing the user interface. React, however, also uses internal objects called "fibers" to hold additional information about the component tree. They may also be considered a part of "virtual DOM" implementation in React. |
|||
|
|||
### Is the Shadow DOM the same as the Virtual DOM? |
|||
|
|||
No, they are different. The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The virtual DOM is a concept implemented by libraries in JavaScript on top of browser APIs. |
|||
|
|||
### What is "React Fiber"? |
|||
|
|||
Fiber is the new reconciliation engine in React 16. Its main goal is to enable incremental rendering of the virtual DOM. [Read more](https://github.com/acdlite/react-fiber-architecture). |
@ -0,0 +1,62 @@ |
|||
--- |
|||
id: faq-state |
|||
title: Component State |
|||
permalink: docs/faq-state.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### What does setState do? |
|||
|
|||
`setState()` schedules an update to a component's `state` object. When state changes, the component responds by re-rendering. |
|||
|
|||
### Why is `setState` is giving me the wrong value? |
|||
|
|||
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need compute values based on the current state (see below for details). |
|||
|
|||
Example of code that will not behave as expected: |
|||
|
|||
```jsx |
|||
incrementCount() { |
|||
// Note: this will *not* work as intended. |
|||
this.setState({count: this.state.count + 1}); |
|||
} |
|||
|
|||
handleSomething() { |
|||
// this.state.count is 1, then we do this: |
|||
this.incrementCount(); |
|||
this.incrementCount(); // state wasn't updated yet, so this sets 2 not 3 |
|||
} |
|||
``` |
|||
|
|||
See below for how to fix this problem. |
|||
|
|||
### How do I update state with values that depend on the current state? |
|||
|
|||
Pass a function instead of an object to setState to ensure the call always uses the most updated version of state (see below). |
|||
|
|||
### What is the difference between passing an object or a function in setState? |
|||
|
|||
Passing an update function allows you to access the current state value inside the updater. Since `setState` calls are batched, this lets you chain updates and ensure they build on top of each other instead of conflicting: |
|||
|
|||
```jsx |
|||
incrementCount() { |
|||
this.setState((prevState) => { |
|||
return {count: prevState.count + 1} |
|||
}); |
|||
} |
|||
|
|||
handleSomething() { |
|||
// this.state.count is 1, then we do this: |
|||
this.incrementCount(); |
|||
this.incrementCount(); // count is now 3 |
|||
} |
|||
``` |
|||
|
|||
[Learn more about setState](/docs/react-component.html#setstate) |
|||
|
|||
### Should I use a state management library like Redux or MobX? |
|||
|
|||
[Maybe.](http://redux.js.org/docs/faq/General.html#general-when-to-use) |
|||
|
|||
It's a good idea to get to know React first, before adding in additional libraries. You can build quite complex applications using only React. |
@ -0,0 +1,25 @@ |
|||
--- |
|||
id: faq-structure |
|||
title: File Structure |
|||
permalink: docs/faq-structure.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### Is there a recommended way to structure React projects? |
|||
|
|||
One common way to structure projects is locate CSS, JS, and tests together inside folders grouped by feature or route. |
|||
|
|||
``` |
|||
FeatureA |
|||
index.js |
|||
ComponentA.js |
|||
ComponentA.css |
|||
ComponentA.test.js |
|||
Helper.js |
|||
Helper.test.js |
|||
FeatureB |
|||
index.js |
|||
ComponentB.js |
|||
ComponentB.test.js |
|||
``` |
@ -0,0 +1,49 @@ |
|||
--- |
|||
id: faq-styling |
|||
title: Styling and CSS |
|||
permalink: docs/faq-styling.html |
|||
layout: docs |
|||
category: FAQ |
|||
--- |
|||
|
|||
### How do I add CSS classes to components? |
|||
|
|||
Pass a string as the `className` prop: |
|||
|
|||
```jsx |
|||
render() { |
|||
return <span className="menu navigation-menu">Menu</span> |
|||
} |
|||
``` |
|||
|
|||
It is common for CSS classes to depend on the component props or state: |
|||
|
|||
```jsx |
|||
render() { |
|||
let className = 'menu'; |
|||
if (this.props.isActive) { |
|||
className += ' menu-active'; |
|||
} |
|||
return <span className={className}>Menu</span> |
|||
} |
|||
``` |
|||
|
|||
If you often find yourself writing code like this, [classnames](https://www.npmjs.com/package/classnames) package can simplify it. |
|||
|
|||
### Can I use inline styles? |
|||
|
|||
Yes, see the docs on styling [here](/docs/dom-elements.html#style). |
|||
|
|||
### Are inline styles bad? |
|||
|
|||
CSS classes are generally more efficient than inline styles. |
|||
|
|||
### What is CSS-in-JS? |
|||
|
|||
CSS-in-JS refers to a pattern where CSS is written with Javascript, then extracted into a stylesheet. |
|||
|
|||
[Comparison of CSS-in-JS Libraries](https://github.com/MicheleBertoli/css-in-js) |
|||
|
|||
### Can I do animations in React? |
|||
|
|||
React can be used to power animations. See [React Transition Group](https://reactcommunity.org/react-transition-group/) and [React Motion](https://github.com/chenglou/react-motion), for example. |
@ -0,0 +1,173 @@ |
|||
--- |
|||
id: static-type-checking |
|||
title: Static Type Checking |
|||
permalink: docs/static-type-checking.html |
|||
prev: typechecking-with-prototypes.html |
|||
next: refs-and-the-dom.html |
|||
--- |
|||
|
|||
Static type checkers like [Flow](https://flowtype.org/) and [TypeScript](https://www.typescriptlang.org/) identify certain types of problems before you even run your code. They can also improve developer workflow by adding features like auto-completion. For this reason, we recommend using Flow or TypeScript instead of `PropTypes` for larger code bases. |
|||
|
|||
## Flow |
|||
|
|||
[Flow](https://flow.org/) is a static type checker for your JavaScript code. It is developed at Facebook and is often used with React. It lets you annotate the variables, functions, and React components with a special type syntax, and catch mistakes early. You can read an [introduction to Flow](https://flow.org/en/docs/getting-started/) to learn its basics. |
|||
|
|||
To use Flow, you need to: |
|||
|
|||
* Add Flow to your project as a dependency. |
|||
* Ensure that Flow syntax is stripped from the compiled code. |
|||
* Add type annotations and run Flow to check them. |
|||
|
|||
We will explain these steps below in detail. |
|||
|
|||
### Adding Flow to a Project |
|||
|
|||
First, navigate to your project directory in the terminal. You will need to run two commands. |
|||
|
|||
If you use [Yarn](https://yarnpkg.com/), run: |
|||
|
|||
```bash |
|||
yarn add --dev flow-bin |
|||
yarn run flow init |
|||
``` |
|||
|
|||
If you use [npm](https://www.npmjs.com/), run: |
|||
|
|||
```bash |
|||
npm install --save-dev flow-bin |
|||
npm run flow init |
|||
``` |
|||
|
|||
The first command installs the latest version of Flow into your project. The second command creates a Flow configuration file that you will need to commit. |
|||
|
|||
Finally, add `flow` to the `"scripts"` section of your `package.json`: |
|||
|
|||
```js{4} |
|||
{ |
|||
// ... |
|||
"scripts": { |
|||
"flow": "flow", |
|||
// ... |
|||
}, |
|||
// ... |
|||
} |
|||
``` |
|||
|
|||
### Stripping Flow Syntax from the Compiled Code |
|||
|
|||
Flow extends the JavaScript language with a special syntax for type annotations. However, browsers aren't aware of this syntax, so we need to make sure it doesn't end up in the compiled JavaScript bundle that is sent to the browser. |
|||
|
|||
The exact way to do this depends on the tools you use to compile JavaScript. |
|||
|
|||
#### Create React App |
|||
|
|||
If your project was set up using [Create React App](https://github.com/facebookincubator/create-react-app), congratulations! The Flow annotations are already being stripped by default so you don't need to do anything else in this step. |
|||
|
|||
#### Babel |
|||
|
|||
>Note: |
|||
> |
|||
>These instructions are *not* for Create React App users. Even though Create React App uses Babel under the hood, it is already configured to understand Flow. Only follow this step if you *don't* use Create React App. |
|||
|
|||
If you manually configured Babel for your project, you will need to install a special preset for Flow. |
|||
|
|||
If you use Yarn, run: |
|||
|
|||
```bash |
|||
yarn add --dev babel-preset-flow |
|||
``` |
|||
|
|||
If you use npm, run: |
|||
|
|||
```bash |
|||
npm install --save-dev babel-preset-flow |
|||
``` |
|||
|
|||
Then add the `flow` preset to your [Babel configuration](http://babeljs.io/docs/usage/babelrc/). For example, if you configure Babel through `.babelrc` file, it could look like this: |
|||
|
|||
```js{3} |
|||
{ |
|||
"presets": [ |
|||
"flow", |
|||
"react" |
|||
] |
|||
} |
|||
``` |
|||
|
|||
This will let you use the Flow syntax in your code. |
|||
|
|||
>Note: |
|||
> |
|||
>Flow does not require the `react` preset, but they are often used together. Flow itself understands JSX syntax out of the box. |
|||
|
|||
#### Other Build Setups |
|||
|
|||
If you don't use either Create React App or Babel, you can use [flow-remove-types](https://github.com/flowtype/flow-remove-types) to strip the type annotations. |
|||
|
|||
### Running Flow |
|||
|
|||
If you followed the instructions above, you should be able to run Flow for the first time. |
|||
|
|||
```bash |
|||
yarn flow |
|||
``` |
|||
|
|||
If you use npm, run: |
|||
|
|||
```bash |
|||
npm run flow |
|||
``` |
|||
|
|||
You should see a message like: |
|||
|
|||
``` |
|||
No errors! |
|||
✨ Done in 0.17s. |
|||
``` |
|||
|
|||
### Adding Flow Type Annotations |
|||
|
|||
By default, Flow only checks the files that include this annotation: |
|||
|
|||
```js |
|||
// @flow |
|||
``` |
|||
|
|||
Typically it is placed at the top of a file. Try adding it to some files in your project and run `yarn flow` or `npm run flow` to see if Flow already found any issues. |
|||
|
|||
There is also [an option](https://flow.org/en/docs/config/options/#toc-all-boolean) to force Flow to check *all* files regardless of the annotation. This can be too noisy for existing projects, but is reasonable for a new project if you want to fully type it with Flow. |
|||
|
|||
Now you're all set! We recommend to check out the following resources to learn more about Flow: |
|||
|
|||
* [Flow Documentation: Type Annotations](https://flow.org/en/docs/types/) |
|||
* [Flow Documentation: Editors](https://flow.org/en/docs/editors/) |
|||
* [Flow Documentation: React](https://flow.org/en/docs/react/) |
|||
* [Linting in Flow](https://medium.com/flow-type/linting-in-flow-7709d7a7e969) |
|||
|
|||
## TypeScript |
|||
|
|||
[TypeScript](https://www.typescriptlang.org/) is a programming language developed by Microsoft. It is a typed superset of JavaScript, and includes its own compiler. |
|||
|
|||
You can learn more about using TypeScript with React [here](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter). |
|||
|
|||
### Using TypeScript with Create React App |
|||
|
|||
[react-scripts-ts](https://www.npmjs.com/package/react-scripts-ts) automatically configures a `create-react-app` project to support TypeScript. You can use it like this: |
|||
|
|||
```bash |
|||
create-react-app my-app --scripts-version=react-scripts-ts |
|||
``` |
|||
|
|||
Note that it is a **third party** project, and is not a part of Create React App. |
|||
|
|||
You can also try [typescript-react-starter](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter). |
|||
|
|||
## Reason |
|||
|
|||
[Reason](https://reasonml.github.io/) is not a new language; it's a new syntax and toolchain powered by the battle-tested language, [OCaml](http://ocaml.org/). Reason gives OCaml a familiar syntax geared toward JavaScript programmers, and caters to the existing NPM/Yarn workflow folks already know. |
|||
|
|||
Reason is developed at Facebook, and is used in some of its products like Messenger. It is still somewhat experimental but it has [dedicated React bindings](https://reasonml.github.io/reason-react/) maintained by Facebook and a [vibrant community](https://reasonml.github.io/community/). |
|||
|
|||
## Other Languages |
|||
|
|||
Note there are other statically typed languages that compile to JavaScript and are thus React compatible. For example, [F#/Fable](http://fable.io) with [elmish-react](https://fable-elmish.github.io/react). Check out their respective sites for more information, and feel free to add more statically typed languages that work with React to this page! |
@ -0,0 +1,35 @@ |
|||
class MarkdownEditor extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.handleChange = this.handleChange.bind(this); |
|||
this.state = { value: 'Type some *markdown* here!' }; |
|||
} |
|||
|
|||
handleChange(e) { |
|||
this.setState({ value: e.target.value }); |
|||
} |
|||
|
|||
getRawMarkup() { |
|||
const md = new Remarkable(); |
|||
return { __html: md.render(this.state.value) }; |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<div className="MarkdownEditor"> |
|||
<h3>Input</h3> |
|||
<textarea |
|||
onChange={this.handleChange} |
|||
defaultValue={this.state.value} |
|||
/> |
|||
<h3>Output</h3> |
|||
<div |
|||
className="content" |
|||
dangerouslySetInnerHTML={this.getRawMarkup()} |
|||
/> |
|||
</div> |
|||
); |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render(<MarkdownEditor />, mountNode); |
@ -0,0 +1,6 @@ |
|||
--- |
|||
title: A Component Using External Plugins |
|||
order: 3 |
|||
--- |
|||
|
|||
React is flexible and provides hooks that allow you to interface with other libraries and frameworks. This example uses **remarkable**, an external Markdown library, to convert the `<textarea>`'s value in real time. |
@ -0,0 +1,14 @@ |
|||
class HelloMessage extends React.Component { |
|||
render() { |
|||
return ( |
|||
<div> |
|||
Hello {this.props.name} |
|||
</div> |
|||
); |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render( |
|||
<HelloMessage name="Taylor" />, |
|||
mountNode |
|||
); |
@ -0,0 +1,8 @@ |
|||
--- |
|||
title: A Simple Component |
|||
order: 0 |
|||
--- |
|||
|
|||
React components implement a `render()` method that takes input data and returns what to display. This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by `render()` via `this.props`. |
|||
|
|||
**JSX is optional and not required to use React.** Try the [Babel REPL](babel://es5-syntax-example) to see the raw JavaScript code produced by the JSX compilation step. |
@ -0,0 +1,30 @@ |
|||
class Timer extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.state = { seconds: 0 }; |
|||
} |
|||
|
|||
tick() { |
|||
this.setState(prevState => ({ |
|||
seconds: prevState.seconds + 1 |
|||
})); |
|||
} |
|||
|
|||
componentDidMount() { |
|||
this.interval = setInterval(() => this.tick(), 1000); |
|||
} |
|||
|
|||
componentWillUnmount() { |
|||
clearInterval(this.interval); |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<div> |
|||
Seconds: {this.state.seconds} |
|||
</div> |
|||
); |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render(<Timer />, mountNode); |
@ -0,0 +1,6 @@ |
|||
--- |
|||
title: A Stateful Component |
|||
order: 1 |
|||
--- |
|||
|
|||
In addition to taking input data (accessed via `this.props`), a component can maintain internal state data (accessed via `this.state`). When a component's state data changes, the rendered markup will be updated by re-invoking `render()`. |
@ -0,0 +1,59 @@ |
|||
class TodoApp extends React.Component { |
|||
constructor(props) { |
|||
super(props); |
|||
this.state = { items: [], text: '' }; |
|||
this.handleChange = this.handleChange.bind(this); |
|||
this.handleSubmit = this.handleSubmit.bind(this); |
|||
} |
|||
|
|||
render() { |
|||
return ( |
|||
<div> |
|||
<h3>TODO</h3> |
|||
<TodoList items={this.state.items} /> |
|||
<form onSubmit={this.handleSubmit}> |
|||
<input |
|||
onChange={this.handleChange} |
|||
value={this.state.text} |
|||
/> |
|||
<button> |
|||
Add #{this.state.items.length + 1} |
|||
</button> |
|||
</form> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
handleChange(e) { |
|||
this.setState({ text: e.target.value }); |
|||
} |
|||
|
|||
handleSubmit(e) { |
|||
e.preventDefault(); |
|||
if (!this.state.text.length) { |
|||
return; |
|||
} |
|||
const newItem = { |
|||
text: this.state.text, |
|||
id: Date.now() |
|||
}; |
|||
this.setState(prevState => ({ |
|||
items: prevState.items.concat(newItem), |
|||
text: '' |
|||
})); |
|||
} |
|||
} |
|||
|
|||
class TodoList extends React.Component { |
|||
render() { |
|||
return ( |
|||
<ul> |
|||
{this.props.items.map(item => ( |
|||
<li key={item.id}>{item.text}</li> |
|||
))} |
|||
</ul> |
|||
); |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render(<TodoApp />, mountNode); |
@ -0,0 +1,6 @@ |
|||
--- |
|||
title: An Application |
|||
order: 2 |
|||
--- |
|||
|
|||
Using `props` and `state`, we can put together a small Todo application. This example uses `state` to track the current list of items as well as the text that the user has entered. Although event handlers appear to be rendered inline, they will be collected and implemented using event delegation. |
@ -0,0 +1,8 @@ |
|||
--- |
|||
title: Component-Based |
|||
order: 1 |
|||
--- |
|||
|
|||
Build encapsulated components that manage their own state, then compose them to make complex UIs. |
|||
|
|||
Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM. |
@ -0,0 +1,8 @@ |
|||
--- |
|||
title: Declarative |
|||
order: 0 |
|||
--- |
|||
|
|||
React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. |
|||
|
|||
Declarative views make your code more predictable and easier to debug. |
@ -0,0 +1,8 @@ |
|||
--- |
|||
title: Learn Once, Write Anywhere |
|||
order: 2 |
|||
--- |
|||
|
|||
We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. |
|||
|
|||
React can also render on the server using Node and power mobile apps using [React Native](https://facebook.github.io/react-native/). |
@ -1,76 +0,0 @@ |
|||
--- |
|||
layout: hero |
|||
title: A JavaScript library for building user interfaces |
|||
id: home |
|||
--- |
|||
|
|||
<section class="light home-section"> |
|||
<div class="marketing-row"> |
|||
<div class="marketing-col"> |
|||
<h3>Declarative</h3> |
|||
<p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p> |
|||
<p>Declarative views make your code more predictable and easier to debug.</p> |
|||
</div> |
|||
<div class="marketing-col"> |
|||
<h3>Component-Based</h3> |
|||
<p>Build encapsulated components that manage their own state, then compose them to make complex UIs.</p> |
|||
<p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p> |
|||
</div> |
|||
<div class="marketing-col"> |
|||
<h3>Learn Once, Write Anywhere</h3> |
|||
<p>We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code.</p> |
|||
<p>React can also render on the server using Node and power mobile apps using <a href="https://facebook.github.io/react-native/">React Native</a>.</p> |
|||
</div> |
|||
</div> |
|||
</section> |
|||
<hr class="home-divider" /> |
|||
<section class="home-section"> |
|||
<div id="examples"> |
|||
<div class="example"> |
|||
<h3>A Simple Component</h3> |
|||
<p> |
|||
React components implement a `render()` method that takes input data and |
|||
returns what to display. This example uses an XML-like syntax called |
|||
JSX. Input data that is passed into the component can be accessed by |
|||
`render()` via `this.props`. |
|||
</p> |
|||
<p> |
|||
<strong>JSX is optional and not required to use React.</strong> |
|||
Try the |
|||
<a href="http://babeljs.io/repl#?babili=false&browsers=&build=&builtIns=false&code_lz=MYGwhgzhAEASCmIQHsCy8pgOb2vAHgC7wB2AJjAErxjCEB0AwsgLYAOyJph0A3gFABIAE6ky8YQAoAlHyEj4hAK7CS0ADxkAlgDcAfAiTI-hABZaI9NsORtLJMC3gBfdQHpt-gNxDn_P_zUtIQAIgDyqPSi5BKS6oYo6Jg40A5OALwARCHwOlokmdBuegA00CzISiSEAHLI4tJeQA&debug=false&circleciRepo=&evaluate=false&lineWrap=false&presets=react&prettier=true&targets=&version=6.26.0">Babel REPL</a> |
|||
to see the raw JavaScript code produced by the JSX compilation step. |
|||
</p> |
|||
<div id="helloExample"></div> |
|||
</div> |
|||
<div class="example"> |
|||
<h3>A Stateful Component</h3> |
|||
<p> |
|||
In addition to taking input data (accessed via `this.props`), a |
|||
component can maintain internal state data (accessed via `this.state`). |
|||
When a component's state data changes, the rendered markup will be |
|||
updated by re-invoking `render()`. |
|||
</p> |
|||
<div id="timerExample"></div> |
|||
</div> |
|||
<div class="example"> |
|||
<h3>An Application</h3> |
|||
<p> |
|||
Using `props` and `state`, we can put together a small Todo application. |
|||
This example uses `state` to track the current list of items as well as |
|||
the text that the user has entered. Although event handlers appear to be |
|||
rendered inline, they will be collected and implemented using event |
|||
delegation. |
|||
</p> |
|||
<div id="todoExample"></div> |
|||
</div> |
|||
<div class="example"> |
|||
<h3>A Component Using External Plugins</h3> |
|||
<p> |
|||
React is flexible and provides hooks that allow you to interface with |
|||
other libraries and frameworks. This example uses <strong>remarkable</strong>, an |
|||
external Markdown library, to convert the textarea's value in real time. |
|||
</p> |
|||
<div id="markdownExample"></div> |
|||
</div> |
|||
</div> |
|||
</section> |
@ -0,0 +1,18 @@ |
|||
function Welcome(props) { |
|||
return <h1>Hello, {props.name}</h1>; |
|||
} |
|||
|
|||
function App() { |
|||
return ( |
|||
<div> |
|||
<Welcome name="Sara" /> |
|||
<Welcome name="Cahal" /> |
|||
<Welcome name="Edite" /> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
ReactDOM.render( |
|||
<App />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,52 @@ |
|||
function formatDate(date) { |
|||
return date.toLocaleDateString(); |
|||
} |
|||
|
|||
function Avatar(props) { |
|||
return ( |
|||
<img className="Avatar" |
|||
src={props.user.avatarUrl} |
|||
alt={props.user.name} /> |
|||
); |
|||
} |
|||
|
|||
function UserInfo(props) { |
|||
return ( |
|||
<div className="UserInfo"> |
|||
<Avatar user={props.user} /> |
|||
<div className="UserInfo-name"> |
|||
{props.user.name} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
function Comment(props) { |
|||
return ( |
|||
<div className="Comment"> |
|||
<UserInfo user={props.author} /> |
|||
<div className="Comment-text"> |
|||
{props.text} |
|||
</div> |
|||
<div className="Comment-date"> |
|||
{formatDate(props.date)} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
const comment = { |
|||
date: new Date(), |
|||
text: 'I hope you enjoy learning React!', |
|||
author: { |
|||
name: 'Hello Kitty', |
|||
avatarUrl: 'http://placekitten.com/g/64/64' |
|||
} |
|||
}; |
|||
ReactDOM.render( |
|||
<Comment |
|||
date={comment.date} |
|||
text={comment.text} |
|||
author={comment.author} />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,40 @@ |
|||
function formatDate(date) { |
|||
return date.toLocaleDateString(); |
|||
} |
|||
|
|||
function Comment(props) { |
|||
return ( |
|||
<div className="Comment"> |
|||
<div className="UserInfo"> |
|||
<img className="Avatar" |
|||
src={props.author.avatarUrl} |
|||
alt={props.author.name} /> |
|||
<div className="UserInfo-name"> |
|||
{props.author.name} |
|||
</div> |
|||
</div> |
|||
<div className="Comment-text"> |
|||
{props.text} |
|||
</div> |
|||
<div className="Comment-date"> |
|||
{formatDate(props.date)} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
const comment = { |
|||
date: new Date(), |
|||
text: 'I hope you enjoy learning React!', |
|||
author: { |
|||
name: 'Hello Kitty', |
|||
avatarUrl: 'http://placekitten.com/g/64/64' |
|||
} |
|||
}; |
|||
ReactDOM.render( |
|||
<Comment |
|||
date={comment.date} |
|||
text={comment.text} |
|||
author={comment.author} />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,9 @@ |
|||
function Welcome(props) { |
|||
return <h1>Hello, {props.name}</h1>; |
|||
} |
|||
|
|||
const element = <Welcome name="Sara" />; |
|||
ReactDOM.render( |
|||
element, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,3 @@ |
|||
const element = <h1>Hello, world!</h1>; |
|||
const container = document.getElementById('root'); |
|||
ReactDOM.render(element, container); |
@ -0,0 +1,4 @@ |
|||
ReactDOM.render( |
|||
<h1>Hello, world!</h1>, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,19 @@ |
|||
function formatName(user) { |
|||
return user.firstName + ' ' + user.lastName; |
|||
} |
|||
|
|||
const user = { |
|||
firstName: 'Harper', |
|||
lastName: 'Perez', |
|||
}; |
|||
|
|||
const element = ( |
|||
<h1> |
|||
Hello, {formatName(user)}! |
|||
</h1> |
|||
); |
|||
|
|||
ReactDOM.render( |
|||
element, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,3 @@ |
|||
function hello() { |
|||
return <div>Hello world!</div>; |
|||
} |
@ -0,0 +1,103 @@ |
|||
const ToDo = (props) => ( |
|||
<tr> |
|||
<td><label>{props.id}</label></td> |
|||
<td><input/></td> |
|||
<td><label>{props.createdAt.toTimeString()}</label></td> |
|||
</tr> |
|||
); |
|||
|
|||
class ToDoList extends React.Component { |
|||
constructor() { |
|||
super(); |
|||
const date = new Date(); |
|||
const todoCounter = 1; |
|||
this.state = { |
|||
todoCounter: todoCounter, |
|||
list: [ |
|||
{ id: todoCounter, createdAt: date }, |
|||
] |
|||
} |
|||
} |
|||
|
|||
sortByEarliest() { |
|||
const sortedList = this.state.list.sort((a, b) => { |
|||
return a.createdAt - b.createdAt; |
|||
}); |
|||
this.setState({ |
|||
list: [...sortedList] |
|||
}) |
|||
} |
|||
|
|||
sortByLatest() { |
|||
const sortedList = this.state.list.sort((a, b) => { |
|||
return b.createdAt - a.createdAt; |
|||
}); |
|||
this.setState({ |
|||
list: [...sortedList] |
|||
}) |
|||
} |
|||
|
|||
addToEnd() { |
|||
const date = new Date(); |
|||
const nextId = this.state.todoCounter + 1; |
|||
const newList = [ |
|||
...this.state.list, |
|||
{ id: nextId, createdAt: date } |
|||
]; |
|||
this.setState({ |
|||
list: newList, |
|||
todoCounter: nextId |
|||
}); |
|||
} |
|||
|
|||
addToStart() { |
|||
const date = new Date(); |
|||
const nextId = this.state.todoCounter + 1; |
|||
const newList = [ |
|||
{ id: nextId, createdAt: date }, |
|||
...this.state.list |
|||
]; |
|||
this.setState({ |
|||
list: newList, |
|||
todoCounter: nextId |
|||
}); |
|||
} |
|||
|
|||
render() { |
|||
return( |
|||
<div> |
|||
<code>key=index</code><br/> |
|||
<button onClick={this.addToStart.bind(this)}> |
|||
Add New to Start |
|||
</button> |
|||
<button onClick={this.addToEnd.bind(this)}> |
|||
Add New to End |
|||
</button> |
|||
<button onClick={this.sortByEarliest.bind(this)}> |
|||
Sort by Earliest |
|||
</button> |
|||
<button onClick={this.sortByLatest.bind(this)}> |
|||
Sort by Latest |
|||
</button> |
|||
<table> |
|||
<tr> |
|||
<th>ID</th><th></th><th>created at</th> |
|||
</tr> |
|||
{ |
|||
this.state.list.map((todo, index) => ( |
|||
<ToDo |
|||
key={index} |
|||
{...todo} |
|||
/> |
|||
)) |
|||
} |
|||
</table> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render( |
|||
<ToDoList />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,103 @@ |
|||
const ToDo = (props) => ( |
|||
<tr> |
|||
<td><label>{props.id}</label></td> |
|||
<td><input/></td> |
|||
<td><label>{props.createdAt.toTimeString()}</label></td> |
|||
</tr> |
|||
); |
|||
|
|||
class ToDoList extends React.Component { |
|||
constructor() { |
|||
super(); |
|||
const date = new Date(); |
|||
const toDoCounter = 1; |
|||
this.state = { |
|||
list: [ |
|||
{ id: toDoCounter, createdAt: date }, |
|||
], |
|||
toDoCounter: toDoCounter |
|||
} |
|||
} |
|||
|
|||
sortByEarliest() { |
|||
const sortedList = this.state.list.sort((a, b) => { |
|||
return a.createdAt - b.createdAt; |
|||
}); |
|||
this.setState({ |
|||
list: [...sortedList] |
|||
}) |
|||
} |
|||
|
|||
sortByLatest() { |
|||
const sortedList = this.state.list.sort((a, b) => { |
|||
return b.createdAt - a.createdAt; |
|||
}); |
|||
this.setState({ |
|||
list: [...sortedList] |
|||
}) |
|||
} |
|||
|
|||
addToEnd() { |
|||
const date = new Date(); |
|||
const nextId = this.state.toDoCounter + 1; |
|||
const newList = [ |
|||
...this.state.list, |
|||
{ id: nextId, createdAt: date } |
|||
]; |
|||
this.setState({ |
|||
list: newList, |
|||
toDoCounter: nextId |
|||
}); |
|||
} |
|||
|
|||
addToStart() { |
|||
const date = new Date(); |
|||
const nextId = this.state.toDoCounter + 1; |
|||
const newList = [ |
|||
{ id: nextId, createdAt: date }, |
|||
...this.state.list |
|||
]; |
|||
this.setState({ |
|||
list: newList, |
|||
toDoCounter: nextId |
|||
}); |
|||
} |
|||
|
|||
render() { |
|||
return( |
|||
<div> |
|||
<code>key=id</code><br/> |
|||
<button onClick={this.addToStart.bind(this)}> |
|||
Add New to Start |
|||
</button> |
|||
<button onClick={this.addToEnd.bind(this)}> |
|||
Add New to End |
|||
</button> |
|||
<button onClick={this.sortByEarliest.bind(this)}> |
|||
Sort by Earliest |
|||
</button> |
|||
<button onClick={this.sortByLatest.bind(this)}> |
|||
Sort by Latest |
|||
</button> |
|||
<table> |
|||
<tr> |
|||
<th>ID</th><th></th><th>created at</th> |
|||
</tr> |
|||
{ |
|||
this.state.list.map((todo, index) => ( |
|||
<ToDo |
|||
key={todo.id} |
|||
{...todo} |
|||
/> |
|||
)) |
|||
} |
|||
</table> |
|||
</div> |
|||
) |
|||
} |
|||
} |
|||
|
|||
ReactDOM.render( |
|||
<ToDoList />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,8 @@ |
|||
<div className="shopping-list"> |
|||
<h1>Shopping List for {props.name}</h1> |
|||
<ul> |
|||
<li>Instagram</li> |
|||
<li>WhatsApp</li> |
|||
<li>Oculus</li> |
|||
</ul> |
|||
</div> |
@ -0,0 +1,154 @@ |
|||
/** |
|||
* Copyright (c) 2013-present, Facebook, Inc. |
|||
* |
|||
* @emails react-core |
|||
*/ |
|||
|
|||
'use strict'; |
|||
|
|||
const {resolve} = require('path'); |
|||
|
|||
module.exports = async ({graphql, boundActionCreators}) => { |
|||
const {createPage, createRedirect} = boundActionCreators; |
|||
|
|||
// Used to detect and prevent duplicate redirects
|
|||
const redirectToSlugMap = {}; |
|||
|
|||
const blogTemplate = resolve(__dirname, '../src/templates/blog.js'); |
|||
const communityTemplate = resolve(__dirname, '../src/templates/community.js'); |
|||
const docsTemplate = resolve(__dirname, '../src/templates/docs.js'); |
|||
const tutorialTemplate = resolve(__dirname, '../src/templates/tutorial.js'); |
|||
|
|||
// Redirect /index.html to root.
|
|||
createRedirect({ |
|||
fromPath: '/index.html', |
|||
redirectInBrowser: true, |
|||
toPath: '/', |
|||
}); |
|||
|
|||
const allMarkdown = await graphql( |
|||
` |
|||
{ |
|||
allMarkdownRemark(limit: 1000) { |
|||
edges { |
|||
node { |
|||
fields { |
|||
redirect |
|||
slug |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
`,
|
|||
); |
|||
|
|||
if (allMarkdown.errors) { |
|||
console.error(allMarkdown.errors); |
|||
|
|||
throw Error(allMarkdown.errors); |
|||
} |
|||
|
|||
allMarkdown.data.allMarkdownRemark.edges.forEach(edge => { |
|||
const slug = edge.node.fields.slug; |
|||
|
|||
if (slug === 'docs/error-decoder.html') { |
|||
// No-op so far as markdown templates go.
|
|||
// Error codes are managed by a page in src/pages
|
|||
// (which gets created by Gatsby during a separate phase).
|
|||
} else if ( |
|||
slug.includes('blog/') || |
|||
slug.includes('community/') || |
|||
slug.includes('contributing/') || |
|||
slug.includes('docs/') || |
|||
slug.includes('tutorial/') || |
|||
slug.includes('warnings/') |
|||
) { |
|||
let template; |
|||
if (slug.includes('blog/')) { |
|||
template = blogTemplate; |
|||
} else if (slug.includes('community/')) { |
|||
template = communityTemplate; |
|||
} else if ( |
|||
slug.includes('contributing/') || |
|||
slug.includes('docs/') || |
|||
slug.includes('warnings/') |
|||
) { |
|||
template = docsTemplate; |
|||
} else if (slug.includes('tutorial/')) { |
|||
template = tutorialTemplate; |
|||
} |
|||
|
|||
const createArticlePage = path => |
|||
createPage({ |
|||
path: path, |
|||
component: template, |
|||
context: { |
|||
slug, |
|||
}, |
|||
}); |
|||
|
|||
// Register primary URL.
|
|||
createArticlePage(slug); |
|||
|
|||
// Register redirects as well if the markdown specifies them.
|
|||
if (edge.node.fields.redirect) { |
|||
let redirect = JSON.parse(edge.node.fields.redirect); |
|||
if (!Array.isArray(redirect)) { |
|||
redirect = [redirect]; |
|||
} |
|||
|
|||
redirect.forEach(fromPath => { |
|||
if (redirectToSlugMap[fromPath] != null) { |
|||
console.error( |
|||
`Duplicate redirect detected from "${fromPath}" to:\n` + |
|||
`* ${redirectToSlugMap[fromPath]}\n` + |
|||
`* ${slug}\n`, |
|||
); |
|||
process.exit(1); |
|||
} |
|||
|
|||
// A leading "/" is required for redirects to work,
|
|||
// But multiple leading "/" will break redirects.
|
|||
// For more context see github.com/reactjs/reactjs.org/pull/194
|
|||
const toPath = slug.startsWith('/') ? slug : `/${slug}`; |
|||
|
|||
redirectToSlugMap[fromPath] = slug; |
|||
createRedirect({ |
|||
fromPath: `/${fromPath}`, |
|||
redirectInBrowser: true, |
|||
toPath, |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
const newestBlogEntry = await graphql( |
|||
` |
|||
{ |
|||
allMarkdownRemark( |
|||
limit: 1 |
|||
filter: {id: {regex: "/blog/"}} |
|||
sort: {fields: [fields___date], order: DESC} |
|||
) { |
|||
edges { |
|||
node { |
|||
fields { |
|||
slug |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
`,
|
|||
); |
|||
const newestBlogNode = newestBlogEntry.data.allMarkdownRemark.edges[0].node; |
|||
|
|||
// Blog landing page should always show the most recent blog entry.
|
|||
createRedirect({ |
|||
fromPath: '/blog/', |
|||
redirectInBrowser: true, |
|||
toPath: newestBlogNode.fields.slug, |
|||
}); |
|||
}; |
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright (c) 2013-present, Facebook, Inc. |
|||
* |
|||
* @emails react-core |
|||
*/ |
|||
|
|||
'use strict'; |
|||
|
|||
const {resolve} = require('path'); |
|||
const webpack = require('webpack'); |
|||
|
|||
module.exports = ({config, stage}) => { |
|||
// See https://github.com/FormidableLabs/react-live/issues/5
|
|||
config.plugin('ignore', () => new webpack.IgnorePlugin(/^(xor|props)$/)); |
|||
|
|||
config.merge({ |
|||
resolve: { |
|||
root: resolve(__dirname, '../src'), |
|||
extensions: ['', '.js', '.jsx', '.json'], |
|||
}, |
|||
}); |
|||
return config; |
|||
}; |
@ -0,0 +1,79 @@ |
|||
/** |
|||
* Copyright (c) 2013-present, Facebook, Inc. |
|||
* |
|||
* @emails react-core |
|||
*/ |
|||
|
|||
'use strict'; |
|||
|
|||
// Parse date information out of blog post filename.
|
|||
const BLOG_POST_FILENAME_REGEX = /([0-9]+)\-([0-9]+)\-([0-9]+)\-(.+)\.md$/; |
|||
|
|||
// Add custom fields to MarkdownRemark nodes.
|
|||
module.exports = exports.onCreateNode = ({node, boundActionCreators, getNode}) => { |
|||
const {createNodeField} = boundActionCreators; |
|||
|
|||
switch (node.internal.type) { |
|||
case 'MarkdownRemark': |
|||
const {permalink, redirect_from} = node.frontmatter; |
|||
const {relativePath} = getNode(node.parent); |
|||
|
|||
let slug = permalink; |
|||
|
|||
if (!slug) { |
|||
if (relativePath.includes('blog')) { |
|||
// Blog posts don't have embedded permalinks.
|
|||
// Their slugs follow a pattern: /blog/<year>/<month>/<day>/<slug>.html
|
|||
// The date portion comes from the file name: <date>-<title>.md
|
|||
const match = BLOG_POST_FILENAME_REGEX.exec(relativePath); |
|||
const year = match[1]; |
|||
const month = match[2]; |
|||
const day = match[3]; |
|||
const filename = match[4]; |
|||
|
|||
slug = `/blog/${year}/${month}/${day}/${filename}.html`; |
|||
|
|||
const date = new Date(year, month - 1, day); |
|||
|
|||
// Blog posts are sorted by date and display the date in their header.
|
|||
createNodeField({ |
|||
node, |
|||
name: 'date', |
|||
value: date.toJSON(), |
|||
}); |
|||
} |
|||
} |
|||
|
|||
if (!slug) { |
|||
slug = `/${relativePath.replace('.md', '.html')}`; |
|||
|
|||
// This should only happen for the partials in /content/home,
|
|||
// But let's log it in case it happens for other files also.
|
|||
console.warn( |
|||
`Warning: No slug found for "${relativePath}". Falling back to default "${slug}".`, |
|||
); |
|||
} |
|||
|
|||
// Used to generate URL to view this content.
|
|||
createNodeField({ |
|||
node, |
|||
name: 'slug', |
|||
value: slug, |
|||
}); |
|||
|
|||
// Used to generate a GitHub edit link.
|
|||
createNodeField({ |
|||
node, |
|||
name: 'path', |
|||
value: relativePath, |
|||
}); |
|||
|
|||
// Used by createPages() above to register redirects.
|
|||
createNodeField({ |
|||
node, |
|||
name: 'redirect', |
|||
value: redirect_from ? JSON.stringify(redirect_from) : '', |
|||
}); |
|||
return; |
|||
} |
|||
}; |
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright (c) 2013-present, Facebook, Inc. |
|||
* |
|||
* @emails react-core |
|||
*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = async ({page, boundActionCreators}) => { |
|||
const {createPage} = boundActionCreators; |
|||
|
|||
return new Promise(resolvePromise => { |
|||
// page.matchPath is a special key that's used for matching pages only on the client.
|
|||
// Explicitly wire up all error code wildcard matches to redirect to the error code page.
|
|||
if (page.path.includes('docs/error-decoder.html')) { |
|||
page.matchPath = 'docs/error-decoder:path?'; |
|||
page.context.slug = 'docs/error-decoder.html'; |
|||
|
|||
createPage(page); |
|||
} |
|||
|
|||
resolvePromise(); |
|||
}); |
|||
}; |
@ -0,0 +1,28 @@ |
|||
const {readdirSync, readFileSync} = require('fs'); |
|||
const {join, resolve} = require('path'); |
|||
|
|||
// Store code snippets in GraphQL for the home page examples.
|
|||
// Snippets will be matched with markdown templates of the same name.
|
|||
exports.sourceNodes = ({graphql, boundActionCreators}) => { |
|||
const {createNode} = boundActionCreators; |
|||
|
|||
const path = resolve(__dirname, '../../content/home/examples'); |
|||
const files = readdirSync(path); |
|||
|
|||
files.forEach(file => { |
|||
if (file.match(/\.js$/)) { |
|||
const code = readFileSync(join(path, file), 'utf8'); |
|||
const id = file.replace(/\.js$/, ''); |
|||
|
|||
createNode({ |
|||
id, |
|||
children: [], |
|||
parent: 'EXAMPLES', |
|||
internal: { |
|||
type: 'ExampleCode', |
|||
contentDigest: JSON.stringify(code), |
|||
}, |
|||
}); |
|||
} |
|||
}); |
|||
}; |
@ -0,0 +1,4 @@ |
|||
{ |
|||
"name": "gatsby-transformer-home-example-code", |
|||
"version": "0.0.1" |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue