Compare commits
363 Commits
v0.4.0
...
0.5-stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b809ffbc4 | ||
|
|
e6912a7a4a | ||
|
|
f1ae3392bd | ||
|
|
94a9a3e752 | ||
|
|
48af9c7bda | ||
|
|
1da10d718d | ||
|
|
ef8bd04b04 | ||
|
|
030835b914 | ||
|
|
abf199d5ff | ||
|
|
1053a1453a | ||
|
|
b8194d92f6 | ||
|
|
18a6b0b94b | ||
|
|
0b31175238 | ||
|
|
6a0bb61b16 | ||
|
|
c065b03b8a | ||
|
|
c32c788e5a | ||
|
|
4a0a14d319 | ||
|
|
a55d44efaf | ||
|
|
08fcec503c | ||
|
|
cd6d43e4c0 | ||
|
|
c329eb6335 | ||
|
|
215988f879 | ||
|
|
fb7e157cba | ||
|
|
8ead6dce76 | ||
|
|
79b09d9597 | ||
|
|
fb1a072739 | ||
|
|
c1c7a601dd | ||
|
|
adad0d72be | ||
|
|
e7f48a6c00 | ||
|
|
d3cee1ee2e | ||
|
|
d47d509637 | ||
|
|
411419c361 | ||
|
|
fc67d5544c | ||
|
|
4faad1a32a | ||
|
|
01b40d84c7 | ||
|
|
67d0f15d1a | ||
|
|
e5f03ae407 | ||
|
|
25140e5a0d | ||
|
|
b5804fa565 | ||
|
|
1bb2651660 | ||
|
|
b21cdac9e3 | ||
|
|
92ce80cf4f | ||
|
|
f3db0006e8 | ||
|
|
ef4d7a37f0 | ||
|
|
64016811d3 | ||
|
|
7b957c880c | ||
|
|
1b835fb5cf | ||
|
|
9f0bbce797 | ||
|
|
c9d20e56d3 | ||
|
|
ce612904ef | ||
|
|
ea1ab5501d | ||
|
|
2c35ed8068 | ||
|
|
c994cc24c3 | ||
|
|
24da1c0023 | ||
|
|
d82181e4b9 | ||
|
|
ba166b9652 | ||
|
|
f756cb3d9c | ||
|
|
cadf8b786c | ||
|
|
953947a617 | ||
|
|
d8c949e4d8 | ||
|
|
243a2b816e | ||
|
|
451176665c | ||
|
|
cff62f8d72 | ||
|
|
3f2ba221ef | ||
|
|
46713c3d7d | ||
|
|
b015204938 | ||
|
|
24f6bed855 | ||
|
|
5325e944e9 | ||
|
|
b488cb3d4b | ||
|
|
087c2afed1 | ||
|
|
b0645bd5d3 | ||
|
|
5a13dd090d | ||
|
|
b0455f4670 | ||
|
|
287f5b578c | ||
|
|
6839704c4b | ||
|
|
5332422239 | ||
|
|
7909c3e71b | ||
|
|
b45c82c256 | ||
|
|
3a5a82fd18 | ||
|
|
1238f5f23a | ||
|
|
ac9f5e9da4 | ||
|
|
58c392ae3b | ||
|
|
aa38ffc22d | ||
|
|
6d300527c8 | ||
|
|
a601c5cc81 | ||
|
|
4549fd7510 | ||
|
|
ef60eee57a | ||
|
|
7a9c13dee8 | ||
|
|
d652dd928a | ||
|
|
c99d6a8013 | ||
|
|
f8c5752472 | ||
|
|
44352a2861 | ||
|
|
7da874d835 | ||
|
|
de9e94de5f | ||
|
|
a151133161 | ||
|
|
042a2723ff | ||
|
|
2e6092b217 | ||
|
|
f658c32df1 | ||
|
|
b16874c5a8 | ||
|
|
b9a657db2c | ||
|
|
dbc613199b | ||
|
|
920c4206f4 | ||
|
|
fdb10c0679 | ||
|
|
325322898c | ||
|
|
27669c09ca | ||
|
|
0c59c57d66 | ||
|
|
26d7c4275a | ||
|
|
2b7a7599bb | ||
|
|
ed9c0ca87c | ||
|
|
68abbacc39 | ||
|
|
84d8e1841a | ||
|
|
a9b3139ff8 | ||
|
|
582b720183 | ||
|
|
0a02b55d95 | ||
|
|
20af6a7ce8 | ||
|
|
7c0f5c3237 | ||
|
|
f43449d333 | ||
|
|
e66287f92e | ||
|
|
f20626f17a | ||
|
|
ab00f8d15c | ||
|
|
58de758a32 | ||
|
|
8beaa211fb | ||
|
|
7c217324a6 | ||
|
|
15c1358aaf | ||
|
|
0a45325621 | ||
|
|
607eeaed4b | ||
|
|
c764adc256 | ||
|
|
27ee9c6eb0 | ||
|
|
8835e9d99f | ||
|
|
3ca507d73f | ||
|
|
3dc1074908 | ||
|
|
94d2bbb221 | ||
|
|
84dea7e971 | ||
|
|
781bbe2916 | ||
|
|
b0ae800d64 | ||
|
|
848a8e1180 | ||
|
|
fc0b68af28 | ||
|
|
c6f831e85f | ||
|
|
58173edb16 | ||
|
|
fc73bf0a0a | ||
|
|
458836abd3 | ||
|
|
5d7633d74c | ||
|
|
8f15eea910 | ||
|
|
d27746ee0b | ||
|
|
d13ce702a8 | ||
|
|
d262285827 | ||
|
|
b5a11a431e | ||
|
|
832d9de037 | ||
|
|
578863881f | ||
|
|
8875e1dc3b | ||
|
|
cd79ed32cb | ||
|
|
1924b7c945 | ||
|
|
d2bf50c63d | ||
|
|
b1dd4149a0 | ||
|
|
208ebd35b7 | ||
|
|
adda400602 | ||
|
|
a9d53dae72 | ||
|
|
ea0cde2cf4 | ||
|
|
e5ba82a44b | ||
|
|
364d6029b6 | ||
|
|
735223fc9f | ||
|
|
be9ac236fd | ||
|
|
ed7fa0ed22 | ||
|
|
3e4302e6ae | ||
|
|
1a38cb9e07 | ||
|
|
71ad5cb37a | ||
|
|
8a7c977942 | ||
|
|
63bacfacfd | ||
|
|
c8ec4595bb | ||
|
|
133ea3df09 | ||
|
|
f729a28f3c | ||
|
|
7ff11c3c88 | ||
|
|
5ab68d9a0d | ||
|
|
58fae896fe | ||
|
|
fea4fec0bc | ||
|
|
d853bbcf77 | ||
|
|
f82f2a0fe2 | ||
|
|
f69112cb3f | ||
|
|
6d77ad4be3 | ||
|
|
7a6a508066 | ||
|
|
cd019871e3 | ||
|
|
63b58cf6b5 | ||
|
|
3bbd966a82 | ||
|
|
5388d70bb1 | ||
|
|
5fd4467bf7 | ||
|
|
aa765e8fa3 | ||
|
|
232b61044c | ||
|
|
426cdbb3ae | ||
|
|
d83fe785c5 | ||
|
|
888cc309e0 | ||
|
|
4ed7b85ed8 | ||
|
|
647731e399 | ||
|
|
cd7d863f20 | ||
|
|
9d0f3623c3 | ||
|
|
e010a2d90b | ||
|
|
d704bc24f4 | ||
|
|
ff2fc586d5 | ||
|
|
78d305eb16 | ||
|
|
6b5c1810c0 | ||
|
|
e41912d6d4 | ||
|
|
97e0926696 | ||
|
|
8df407deb8 | ||
|
|
2ba405d5f8 | ||
|
|
658f41cb30 | ||
|
|
ebc0d09595 | ||
|
|
f7ea031dac | ||
|
|
b56b5885d0 | ||
|
|
a4c23d328c | ||
|
|
3cf14e8f9b | ||
|
|
c8886a0424 | ||
|
|
4f0dea3e7e | ||
|
|
9dd8ef4777 | ||
|
|
65c4ef91c7 | ||
|
|
32d3d7774a | ||
|
|
8664c8ac57 | ||
|
|
dea0cc01cf | ||
|
|
80f1590265 | ||
|
|
c25c5b543b | ||
|
|
8852b86ad8 | ||
|
|
a42fd30fc2 | ||
|
|
406dcbd8da | ||
|
|
de61f9fd81 | ||
|
|
57fe412619 | ||
|
|
b4ff29ac78 | ||
|
|
ba460de7ed | ||
|
|
c7768fde5d | ||
|
|
15f84a391d | ||
|
|
2b9c34b5c7 | ||
|
|
403b087e97 | ||
|
|
75aee1714b | ||
|
|
c41e86c990 | ||
|
|
4d8f0449d9 | ||
|
|
0db4077c3a | ||
|
|
f88aa35187 | ||
|
|
7d34c09e17 | ||
|
|
e11c4ecbaf | ||
|
|
553ed1416c | ||
|
|
688f5051e6 | ||
|
|
adb666e67f | ||
|
|
07e2072692 | ||
|
|
1c14cd6c8b | ||
|
|
744b54a829 | ||
|
|
a90c463abe | ||
|
|
6bf21f1610 | ||
|
|
364ee1ffae | ||
|
|
88faef3ba9 | ||
|
|
bcc6b524fb | ||
|
|
61b38b9f05 | ||
|
|
fce57abeca | ||
|
|
946e9b0c80 | ||
|
|
748ed6cd81 | ||
|
|
49f174cdad | ||
|
|
6ca8d31c83 | ||
|
|
aa1fa7468b | ||
|
|
2d048f1f34 | ||
|
|
3d1cc16a9b | ||
|
|
cbe86e04b3 | ||
|
|
a558e560bd | ||
|
|
cfe4152b1d | ||
|
|
91c2a8d90b | ||
|
|
2c8f907b2c | ||
|
|
669f4b867f | ||
|
|
5fae286cf4 | ||
|
|
a2c90aad86 | ||
|
|
898621d0a1 | ||
|
|
e1c1d869de | ||
|
|
25e2cd0db6 | ||
|
|
1f8ef4c903 | ||
|
|
d9511d817a | ||
|
|
2fda70fb4a | ||
|
|
02f618d52c | ||
|
|
61c47e4cae | ||
|
|
e6b216bdbb | ||
|
|
192727e152 | ||
|
|
cb00d3e66c | ||
|
|
987e5e8f13 | ||
|
|
df0bc8c3af | ||
|
|
983120102c | ||
|
|
86c0b69390 | ||
|
|
d5989a0de4 | ||
|
|
1b747c526c | ||
|
|
5cbabdf4c9 | ||
|
|
9ef4e74ba2 | ||
|
|
0321171113 | ||
|
|
d542621155 | ||
|
|
4bbf8acc9b | ||
|
|
a21556314d | ||
|
|
99d3d7f914 | ||
|
|
86d9e0a97a | ||
|
|
db0ff96200 | ||
|
|
808e625d9d | ||
|
|
dc06704ec7 | ||
|
|
5ef3c1b09b | ||
|
|
fe451c30f8 | ||
|
|
6f2848f4a6 | ||
|
|
d63ce62916 | ||
|
|
c7d6a5ae4d | ||
|
|
d5e970b93f | ||
|
|
4cb49f5561 | ||
|
|
c347b720a9 | ||
|
|
27a1729f6d | ||
|
|
a1f5c1dee7 | ||
|
|
20179b7991 | ||
|
|
adffa9b0f4 | ||
|
|
2e37f65bdc | ||
|
|
2e43de20cc | ||
|
|
a41aa76ef3 | ||
|
|
bdf2a9bb12 | ||
|
|
8d48610b7e | ||
|
|
759425fc90 | ||
|
|
2ee66262db | ||
|
|
260d90ba02 | ||
|
|
492407bcc9 | ||
|
|
ddb0ef98f7 | ||
|
|
8dd4428c55 | ||
|
|
795a84d60f | ||
|
|
947e17154a | ||
|
|
7f8b2885d9 | ||
|
|
d1c5cda93f | ||
|
|
975b5d978f | ||
|
|
f1231e60b0 | ||
|
|
4deb0d619c | ||
|
|
cf3ff07f92 | ||
|
|
bbb4a367be | ||
|
|
63d6cc013e | ||
|
|
d1d2d8d463 | ||
|
|
74cfc9c274 | ||
|
|
add809be21 | ||
|
|
579d86f024 | ||
|
|
73ceb5a401 | ||
|
|
2b9dd04f4d | ||
|
|
4f53fbf1a2 | ||
|
|
64d72f8c4b | ||
|
|
50a00662cf | ||
|
|
d7fcbe0f96 | ||
|
|
0441d4c7f5 | ||
|
|
d9aa2bd12c | ||
|
|
222faf4544 | ||
|
|
36fbd8d941 | ||
|
|
547079763e | ||
|
|
a7dfe04406 | ||
|
|
bf275a9097 | ||
|
|
507e58ed96 | ||
|
|
d9c0be408b | ||
|
|
5beb481145 | ||
|
|
7ef5172d80 | ||
|
|
4ab62a6bd2 | ||
|
|
07427ae9d0 | ||
|
|
8f55d94d40 | ||
|
|
e6812d7e36 | ||
|
|
75ce576d3d | ||
|
|
fa7cc57a6d | ||
|
|
fd2125ee94 | ||
|
|
52e622f1db | ||
|
|
3d7ac69c39 | ||
|
|
e379f8ec03 | ||
|
|
dbdf1cc296 | ||
|
|
dd14fdfdc5 | ||
|
|
fc6a567e0e | ||
|
|
96bd63cc4b | ||
|
|
169b172ffc | ||
|
|
ec67076090 | ||
|
|
9221b15bff |
21
.mailmap
Normal file
@@ -0,0 +1,21 @@
|
||||
Ben Newman <bn@cs.stanford.edu> <benjamn@fb.com>
|
||||
Dan Schafer <dschafer@fb.com>
|
||||
Harry Hull <harry.hull1@gmail.com>
|
||||
Jeff Morrison <jeff@anafx.com> <Jeff@anafx.com>
|
||||
Jeff Morrison <jeff@anafx.com> JeffMo <jeffmo@fb.com>
|
||||
Jeffrey Lin <lin.jeffrey@gmail.com> <jeffreylin@fb.com>
|
||||
Jordan Walke <jordojw@gmail.com>
|
||||
Jordan Walke <jordojw@gmail.com> <jordanjcw@fb.com>
|
||||
Laurence Rowe <l@lrowe.co.uk> <laurence@lrowe.co.uk>
|
||||
Nick Gavalas <njg57@cornell.edu>
|
||||
Paul O’Shannessy <paul@oshannessy.com> <poshannessy@fb.com>
|
||||
Paul Shen <paul@mnml0.com> <paulshen@fb.com>
|
||||
Pete Hunt <floydophone@gmail.com>
|
||||
Pete Hunt <floydophone@gmail.com> <pete.hunt@fb.com>
|
||||
Pete Hunt <floydophone@gmail.com> <pete@instagram.com>
|
||||
Sander Spies <sandermail@gmail.com>
|
||||
Sebastian Markbåge <sebastian@calyptus.eu> <sema@fb.com>
|
||||
Stoyan Stefanov <ssttoo@ymail.com>
|
||||
Timothy Yung <yungsters@gmail.com> <yungsters@fb.com>
|
||||
Vjeux <vjeuxx@gmail.com>
|
||||
Vjeux <vjeuxx@gmail.com> <vjeux@fb.com>
|
||||
14
.travis.yml
@@ -1,3 +1,15 @@
|
||||
---
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- '0.10'
|
||||
after_script:
|
||||
- curl -F "react=@build/react.js" -F "react.min=@build/react.min.js" -F "transformer=@build/JSXTransformer.js"
|
||||
-F "react-with-addons=@build/react-with-addons.js" -F "react-with-addons.min=@build/react-with-addons.min.js"
|
||||
-F "commit=$TRAVIS_COMMIT" -F "date=`git log --format='%ct' -1`" -F "pull_request=$TRAVIS_PULL_REQUEST"
|
||||
-F "token=$SECRET_TOKEN" -F "branch=$TRAVIS_BRANCH" $SERVER
|
||||
env:
|
||||
global:
|
||||
# SERVER
|
||||
- secure: qPvsJ46XzGrdIuPA70b55xQNGF8jcK7N1LN5CCQYYocXLa+fBrl+fTE77QvehOPhqwJXcj6kOxI+sY0KrVwV7gmq2XY2HZGWUSCxTN0SZlNIzqPA80Y7G/yOjA4PUt8LKgP+8tptyhTAY56qf+hgW8BoLiKOdztYF2p+3zXOLuA=
|
||||
# SECRET_TOKEN
|
||||
- secure: dkpPW+VnoqC/okhRdV90m36NcyBFhcwEKL3bNFExAwi0dXnFao8RoFlvnwiPlA23h2faROkMIetXlti6Aju08BgUFV+f9aL6vLyU7gUent4Nd3413zf2fwDtXIWIETg6uLnOpSykGKgCAT/hY3Q2oPLqOoY0OxfgnbqwxkxljrE=
|
||||
|
||||
50
AUTHORS
Normal file
@@ -0,0 +1,50 @@
|
||||
Alexander Solovyov <alexander@solovyov.net>
|
||||
Andrew Zich <azich@fb.com>
|
||||
Andrey Popp <8mayday@gmail.com>
|
||||
Ben Alpert <spicyjalapeno@gmail.com>
|
||||
Ben Newman <bn@cs.stanford.edu>
|
||||
Brian Rue <brian@rollbar.com>
|
||||
Cam Spiers <camspiers@gmail.com>
|
||||
Cat Chen <catchen@fb.com>
|
||||
Cheng Lou <chenglou92@gmail.com>
|
||||
Christian Roman <chroman16@gmail.com>
|
||||
Clay Allsopp <clay.allsopp@gmail.com>
|
||||
Connor McSheffrey <connor.mcsheffrey@gmail.com>
|
||||
Dan Schafer <dschafer@fb.com>
|
||||
Daniel Gasienica <dgasienica@zynga.com>
|
||||
Daniel Miladinov <dmiladinov@wingspan.com>
|
||||
Danny Ben-David <dannybd@fb.com>
|
||||
David Hu <davidhu91@gmail.com>
|
||||
Eric Clemmons <eric@smarterspam.com>
|
||||
Greg Roodt <groodt@gmail.com>
|
||||
Harry Hull <harry.hull1@gmail.com>
|
||||
Hugo Jobling <me@thisishugo.com>
|
||||
Ian Obermiller <iano@fb.com>
|
||||
Isaac Salier-Hellendag <isaac@fb.com>
|
||||
Jakub Malinowski <jakubmal@gmail.com>
|
||||
James Ide <ide@fb.com>
|
||||
Jamie Wong <jamie.lf.wong@gmail.com>
|
||||
Jan Kassens <jkassens@fb.com>
|
||||
Jeff Morrison <jeff@anafx.com>
|
||||
Jeffrey Lin <lin.jeffrey@gmail.com>
|
||||
Jordan Walke <jordojw@gmail.com>
|
||||
Josh Duck <josh@fb.com>
|
||||
Keito Uchiyama <keito@fb.com>
|
||||
Kunal Mehta <k.mehta@berkeley.edu>
|
||||
Laurence Rowe <l@lrowe.co.uk>
|
||||
Marshall Roch <mroch@fb.com>
|
||||
Martin Konicek <mkonicek@fb.com>
|
||||
Mathieu M-Gosselin <mathieumg@gmail.com>
|
||||
Nick Gavalas <njg57@cornell.edu>
|
||||
Owen Coutts <owenc@fb.com>
|
||||
Paul O’Shannessy <paul@oshannessy.com>
|
||||
Paul Seiffert <paul.seiffert@gmail.com>
|
||||
Paul Shen <paul@mnml0.com>
|
||||
Pete Hunt <floydophone@gmail.com>
|
||||
Peter Cottle <pcottle@fb.com>
|
||||
Sander Spies <sandermail@gmail.com>
|
||||
Sebastian Markbåge <sebastian@calyptus.eu>
|
||||
Stoyan Stefanov <ssttoo@ymail.com>
|
||||
Timothy Yung <yungsters@gmail.com>
|
||||
Vjeux <vjeuxx@gmail.com>
|
||||
Zach Bruggeman <zbruggeman@me.com>
|
||||
74
CHANGELOG.md
@@ -1,3 +1,75 @@
|
||||
## 0.5.2, 0.4.2 (December 18, 2013)
|
||||
|
||||
### React
|
||||
|
||||
* Fixed a potential XSS vulnerability when using user content as a `key`: [CVE-2013-7035](https://groups.google.com/forum/#!topic/reactjs/OIqxlB2aGfU)
|
||||
|
||||
|
||||
## 0.5.1 (October 29, 2013)
|
||||
|
||||
### React
|
||||
|
||||
* Fixed bug with `<input type="range">` and selection events.
|
||||
* Fixed bug with selection and focus.
|
||||
* Made it possible to unmount components from the document root.
|
||||
* Fixed bug for `disabled` attribute handling on non-`<input>` elements.
|
||||
|
||||
### React with Addons
|
||||
|
||||
* Fixed bug with transition and animation event detection.
|
||||
|
||||
|
||||
## 0.5.0 (October 16, 2013)
|
||||
|
||||
### React
|
||||
|
||||
* Memory usage improvements - reduced allocations in core which will help with GC pauses
|
||||
* Performance improvements - in addition to speeding things up, we made some tweaks to stay out of slow path code in V8 and Nitro.
|
||||
* Standardized prop -> DOM attribute process. This previously resulting in additional type checking and overhead as well as confusing cases for users. Now we will always convert your value to a string before inserting it into the DOM.
|
||||
* Support for Selection events.
|
||||
* Support for [Composition events](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent).
|
||||
* Support for additional DOM properties (`charSet`, `content`, `form`, `httpEquiv`, `rowSpan`, `autoCapitalize`).
|
||||
* Support for additional SVG properties (`rx`, `ry`).
|
||||
* Support for using `getInitialState` and `getDefaultProps` in mixins.
|
||||
* Support mounting into iframes.
|
||||
* Bug fixes for controlled form components.
|
||||
* Bug fixes for SVG element creation.
|
||||
* Added `React.version`.
|
||||
* Added `React.isValidClass` - Used to determine if a value is a valid component constructor.
|
||||
* Removed `React.autoBind` - This was deprecated in v0.4 and now properly removed.
|
||||
* Renamed `React.unmountAndReleaseReactRootNode` to `React.unmountComponentAtNode`.
|
||||
* Began laying down work for refined performance analysis.
|
||||
* Better support for server-side rendering - [react-page](https://github.com/facebook/react-page) has helped improve the stability for server-side rendering.
|
||||
* Made it possible to use React in environments enforcing a strict [Content Security Policy](https://developer.mozilla.org/en-US/docs/Security/CSP/Introducing_Content_Security_Policy). This also makes it possible to use React to build Chrome extensions.
|
||||
|
||||
### React with Addons (New!)
|
||||
|
||||
* Introduced a separate build with several "addons" which we think can help improve the React experience. We plan to deprecate this in the long-term, instead shipping each as standalone pieces. [Read more in the docs](http://facebook.github.io/react/docs/addons.html).
|
||||
|
||||
### JSX
|
||||
|
||||
* No longer transform `class` to `className` as part of the transform! This is a breaking change - if you were using `class`, you *must* change this to `className` or your components will be visually broken.
|
||||
* Added warnings to the in-browser transformer to make it clear it is not intended for production use.
|
||||
* Improved compatibility for Windows
|
||||
* Improved support for maintaining line numbers when transforming.
|
||||
|
||||
|
||||
## 0.4.1 (July 26, 2013)
|
||||
|
||||
### React
|
||||
|
||||
* `setState` callbacks are now executed in the scope of your component.
|
||||
* `click` events now work on Mobile Safari.
|
||||
* Prevent a potential error in event handling if `Object.prototype` is extended.
|
||||
* Don't set DOM attributes to the string `"undefined"` on update when previously defined.
|
||||
* Improved support for `<iframe>` attributes.
|
||||
* Added checksums to detect and correct cases where server-side rendering markup mismatches what React expects client-side.
|
||||
|
||||
### JSXTransformer
|
||||
|
||||
* Improved environment detection so it can be run in a non-browser environment.
|
||||
|
||||
|
||||
## 0.4.0 (July 17, 2013)
|
||||
|
||||
### React
|
||||
@@ -16,7 +88,7 @@
|
||||
|
||||
* Support for comment nodes `<div>{/* this is a comment and won't be rendered */}</div>`
|
||||
* Children are now transformed directly into arguments instead of being wrapped in an array
|
||||
E.g. `<div><Component1/><Component2></div>` is transformed into `React.DOM.div(null, Component1(null), Component2(null))`.
|
||||
E.g. `<div><Component1/><Component2/></div>` is transformed into `React.DOM.div(null, Component1(null), Component2(null))`.
|
||||
Previously this would be transformed into `React.DOM.div(null, [Component1(null), Component2(null)])`.
|
||||
If you were using React without JSX previously, your code should still work.
|
||||
|
||||
|
||||
27
Gruntfile.js
@@ -52,27 +52,48 @@ module.exports = function(grunt) {
|
||||
|
||||
grunt.registerMultiTask('npm', npmTask);
|
||||
|
||||
grunt.registerTask('build:basic', ['jsx:debug', 'browserify:basic']);
|
||||
// Check that the version we're exporting is the same one we expect in the
|
||||
// package. This is not an ideal way to do this, but makes sure that we keep
|
||||
// them in sync.
|
||||
var reactVersionExp = /\bReact\.version\s*=\s*['"]([^'"]+)['"];/;
|
||||
grunt.registerTask('version-check', function() {
|
||||
var version = reactVersionExp.exec(
|
||||
grunt.file.read('./build/modules/React.js')
|
||||
)[1];
|
||||
var expectedVersion = grunt.config.data.pkg.version;
|
||||
if (version !== expectedVersion) {
|
||||
grunt.log.error('Versions do not match. Expected %s, saw %s', expectedVersion, version);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('build:basic', ['jsx:debug', 'version-check', 'browserify:basic']);
|
||||
grunt.registerTask('build:addons', ['jsx:debug', 'browserify:addons']);
|
||||
grunt.registerTask('build:transformer', ['jsx:debug', 'browserify:transformer']);
|
||||
grunt.registerTask('build:min', ['jsx:release', 'browserify:min']);
|
||||
grunt.registerTask('build:min', ['jsx:release', 'version-check', 'browserify:min']);
|
||||
grunt.registerTask('build:addons-min', ['jsx:debug', 'browserify:addonsMin']);
|
||||
grunt.registerTask('build:test', [
|
||||
'jsx:jasmine',
|
||||
'jsx:test',
|
||||
'version-check',
|
||||
'populist:jasmine',
|
||||
'populist:test'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test', ['build:test', 'phantom:run']);
|
||||
grunt.registerTask('test', ['build:test', 'build:basic', 'phantom:run']);
|
||||
grunt.registerTask('npm:test', ['build', 'npm:pack']);
|
||||
|
||||
// Optimized build task that does all of our builds. The subtasks will be run
|
||||
// in order so we can take advantage of that and only run jsx:debug once.
|
||||
grunt.registerTask('build', [
|
||||
'jsx:debug',
|
||||
'version-check',
|
||||
'browserify:basic',
|
||||
'browserify:transformer',
|
||||
'browserify:addons',
|
||||
'jsx:release',
|
||||
'browserify:min',
|
||||
'browserify:addonsMin',
|
||||
'copy:react_docs',
|
||||
'compare_size'
|
||||
]);
|
||||
|
||||
28
README.md
@@ -2,21 +2,21 @@
|
||||
|
||||
React is a JavaScript library for building user interfaces.
|
||||
|
||||
* **Declarative:** React uses a declarative paradigm that makes it easier to reason about your application.
|
||||
* **Efficient:** React computes the minimal set of changes necessary to keep your DOM up-to-date.
|
||||
* **Flexible:** React works with the libraries and frameworks that you already know.
|
||||
* **Just the UI:** Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project.
|
||||
* **Virtual DOM:** React uses a *virtual DOM* diff implementation for ultra-high performance. It can also render on the server using Node.js — no heavy browser DOM required.
|
||||
* **Data flow:** React implements one-way reactive data flow which reduces boilerplate and is easier to reason about than traditional data binding.
|
||||
|
||||
[Learn how to use React in your own project.](http://facebook.github.io/react/docs/getting-started.html)
|
||||
|
||||
## Examples
|
||||
|
||||
We have several examples [on the website](http://facebook.github.io/react). Here is the first one to get you started:
|
||||
We have several examples [on the website](http://facebook.github.io/react/). Here is the first one to get you started:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
var HelloMessage = React.createClass({
|
||||
render: function() {
|
||||
return <div>{'Hello ' + this.props.name}</div>;
|
||||
return <div>Hello {this.props.name}</div>;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,20 +28,20 @@ React.renderComponent(
|
||||
|
||||
This example will render "Hello John" into a container on the page.
|
||||
|
||||
You'll notice that we used an XML-like syntax; [we call it JSX](http://facebook.github.io/react/docs/syntax.html). JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML. A simple transform is included with React that allows converting JSX into native JavaScript for browsers to digest.
|
||||
You'll notice that we used an XML-like syntax; [we call it JSX](http://facebook.github.io/react/docs/jsx-in-depth.html). JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML. A simple transform is included with React that allows converting JSX into native JavaScript for browsers to digest.
|
||||
|
||||
## Installation
|
||||
|
||||
The fastest way to get started is to serve JavaScript from the CDN:
|
||||
The fastest way to get started is to serve JavaScript from the CDN (also available on [CDNJS](http://cdnjs.com/#react)):
|
||||
|
||||
```html
|
||||
<!-- The core React library -->
|
||||
<script src="http://fb.me/react-0.3.2.min.js"></script>
|
||||
<script src="http://fb.me/react-0.5.2.js"></script>
|
||||
<!-- In-browser JSX transformer, remove when pre-compiling JSX. -->
|
||||
<script src="http://fb.me/JSXTransformer-0.3.2.js"></script>
|
||||
<script src="http://fb.me/JSXTransformer-0.5.2.js"></script>
|
||||
```
|
||||
|
||||
We've also built a [starter kit](http://facebook.github.io/react/downloads/react-0.3.2.zip) which might be useful if this is your first time using React. It includes a webpage with an example of using React with live code.
|
||||
We've also built a [starter kit](http://facebook.github.io/react/downloads/react-0.5.2.zip) which might be useful if this is your first time using React. It includes a webpage with an example of using React with live code.
|
||||
|
||||
If you'd like to use [bower](http://bower.io), it's as easy as:
|
||||
|
||||
@@ -51,7 +51,7 @@ bower install --save react
|
||||
|
||||
## Contribute
|
||||
|
||||
The main purpose of this repository is to continue to evolve React core, making it faster and easier to use. If you're interested in helping with that, then keep reading. If you're not interested in helping right now that's ok too :) Any feedback you have about using React would be greatly appreciated.
|
||||
The main purpose of this repository is to continue to evolve React core, making it faster and easier to use. If you're interested in helping with that, then keep reading. If you're not interested in helping right now that's ok too. :) Any feedback you have about using React would be greatly appreciated.
|
||||
|
||||
### Building Your Copy of React
|
||||
|
||||
@@ -81,12 +81,10 @@ At this point, you should now have a `build/` directory populated with everythin
|
||||
We use grunt to automate many tasks. Run `grunt -h` to see a mostly complete listing. The important ones to know:
|
||||
|
||||
```sh
|
||||
# Create test build & run tests with PhantomJS
|
||||
# Build and run tests with PhantomJS
|
||||
grunt test
|
||||
# Lint the core library code with JSHint
|
||||
# Lint the code with JSHint
|
||||
grunt lint
|
||||
# Lint package code
|
||||
grunt lint:package
|
||||
# Wipe out build directory
|
||||
grunt clean
|
||||
```
|
||||
|
||||
48
bin/jsx
@@ -2,53 +2,11 @@
|
||||
"use strict";
|
||||
|
||||
var visitors = require('../vendor/fbtransform/visitors').transformVisitors;
|
||||
var transform = require('../vendor/fbtransform/lib/transform').transform;
|
||||
var propagate = require("../vendor/constants").propagate;
|
||||
var transform = require('jstransform').transform;
|
||||
|
||||
require("commoner").resolve(function(id) {
|
||||
var context = this;
|
||||
|
||||
// Note that the result of context.getProvidedP() is cached for the
|
||||
// duration of the build, so it is both consistent and cheap to
|
||||
// evaluate multiple times.
|
||||
return context.getProvidedP().then(function(idToPath) {
|
||||
// If a module declares its own identifier using @providesModule
|
||||
// then that identifier will be a key in the idToPath object.
|
||||
if (idToPath.hasOwnProperty(id)) {
|
||||
return context.readFileP(idToPath[id]);
|
||||
}
|
||||
|
||||
// Otherwise assume the identifier maps directly to a path in the
|
||||
// filesystem.
|
||||
return context.readModuleP(id);
|
||||
});
|
||||
|
||||
return this.readModuleP(id);
|
||||
}).process(function(id, source) {
|
||||
var context = this;
|
||||
var constants = context.config.constants || {};
|
||||
|
||||
// This is where JSX, ES6, etc. desugaring happens.
|
||||
source = transform(visitors.react, source).code;
|
||||
|
||||
// Constant propagation means removing any obviously dead code after
|
||||
// replacing constant expressions with literal (boolean) values.
|
||||
source = propagate(constants, source);
|
||||
|
||||
if (context.config.mocking) {
|
||||
// Make sure there is exactly one newline at the end of the module.
|
||||
source = source.replace(/\s+$/m, "\n");
|
||||
|
||||
return context.getProvidedP().then(function(idToPath) {
|
||||
if (id !== "mock-modules" &&
|
||||
id !== "mocks" &&
|
||||
idToPath.hasOwnProperty("mock-modules")) {
|
||||
return source + '\nrequire("mock-modules").register(' +
|
||||
JSON.stringify(id) + ', module);\n';
|
||||
}
|
||||
|
||||
return source;
|
||||
});
|
||||
}
|
||||
|
||||
return source;
|
||||
return transform(visitors.react, source).code;
|
||||
});
|
||||
|
||||
55
bin/jsx-internal
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
var visitors = require('../vendor/fbtransform/visitors').transformVisitors;
|
||||
var transform = require('jstransform').transform;
|
||||
var propagate = require("../vendor/constants").propagate;
|
||||
|
||||
require("commoner").resolve(function(id) {
|
||||
var context = this;
|
||||
|
||||
// Note that the result of context.getProvidedP() is cached for the
|
||||
// duration of the build, so it is both consistent and cheap to
|
||||
// evaluate multiple times.
|
||||
return context.getProvidedP().then(function(idToPath) {
|
||||
// If a module declares its own identifier using @providesModule
|
||||
// then that identifier will be a key in the idToPath object.
|
||||
if (idToPath.hasOwnProperty(id)) {
|
||||
return context.readFileP(idToPath[id]);
|
||||
}
|
||||
|
||||
// Otherwise assume the identifier maps directly to a path in the
|
||||
// filesystem.
|
||||
return context.readModuleP(id);
|
||||
});
|
||||
|
||||
}).process(function(id, source) {
|
||||
var context = this;
|
||||
var constants = context.config.constants || {};
|
||||
|
||||
// This is where JSX, ES6, etc. desugaring happens.
|
||||
source = transform(visitors.react, source).code;
|
||||
|
||||
// Constant propagation means removing any obviously dead code after
|
||||
// replacing constant expressions with literal (boolean) values.
|
||||
source = propagate(constants, source);
|
||||
|
||||
if (context.config.mocking) {
|
||||
// Make sure there is exactly one newline at the end of the module.
|
||||
source = source.replace(/\s+$/m, "\n");
|
||||
|
||||
return context.getProvidedP().then(function(idToPath) {
|
||||
if (id !== "mock-modules" &&
|
||||
id !== "mocks" &&
|
||||
id !== "test/all" &&
|
||||
idToPath.hasOwnProperty("mock-modules")) {
|
||||
return source + '\nrequire("mock-modules").register(' +
|
||||
JSON.stringify(id) + ', module);\n';
|
||||
}
|
||||
|
||||
return source;
|
||||
});
|
||||
}
|
||||
|
||||
return source;
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'rake'
|
||||
|
||||
# jekyll, which builds it all
|
||||
gem 'jekyll', '~>1.0'
|
||||
gem 'jekyll', '~>1.3.0'
|
||||
|
||||
# JSON
|
||||
gem 'json'
|
||||
@@ -14,3 +16,6 @@ gem 'rb-fsevent'
|
||||
|
||||
# Redcarpet for Markdown
|
||||
gem 'redcarpet'
|
||||
|
||||
# For markdown header cleanup
|
||||
gem 'sanitize'
|
||||
|
||||
@@ -4,34 +4,47 @@ GEM
|
||||
classifier (1.3.3)
|
||||
fast-stemmer (>= 1.0.0)
|
||||
colorator (0.1)
|
||||
commander (4.1.3)
|
||||
commander (4.1.5)
|
||||
highline (~> 1.6.11)
|
||||
directory_watcher (1.4.1)
|
||||
fast-stemmer (1.0.2)
|
||||
highline (1.6.19)
|
||||
jekyll (1.0.2)
|
||||
ffi (1.9.3)
|
||||
highline (1.6.20)
|
||||
jekyll (1.3.0)
|
||||
classifier (~> 1.3)
|
||||
colorator (~> 0.1)
|
||||
commander (~> 4.1.3)
|
||||
directory_watcher (~> 1.4.1)
|
||||
kramdown (~> 1.0.2)
|
||||
liquid (~> 2.3)
|
||||
maruku (~> 0.5)
|
||||
liquid (~> 2.5.2)
|
||||
listen (~> 1.3)
|
||||
maruku (~> 0.6.0)
|
||||
pygments.rb (~> 0.5.0)
|
||||
safe_yaml (~> 0.7.0)
|
||||
json (1.8.0)
|
||||
kramdown (1.0.2)
|
||||
liquid (2.5.0)
|
||||
redcarpet (~> 2.3.0)
|
||||
safe_yaml (~> 0.9.7)
|
||||
json (1.8.1)
|
||||
liquid (2.5.4)
|
||||
listen (1.3.1)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
rb-kqueue (>= 0.2)
|
||||
maruku (0.6.1)
|
||||
syntax (>= 1.0.0)
|
||||
mini_portile (0.5.2)
|
||||
nokogiri (1.6.0)
|
||||
mini_portile (~> 0.5.0)
|
||||
posix-spawn (0.3.6)
|
||||
pygments.rb (0.5.0)
|
||||
pygments.rb (0.5.4)
|
||||
posix-spawn (~> 0.3.6)
|
||||
yajl-ruby (~> 1.1.0)
|
||||
rake (10.1.0)
|
||||
rb-fsevent (0.9.3)
|
||||
redcarpet (2.2.2)
|
||||
safe_yaml (0.7.1)
|
||||
sass (3.2.9)
|
||||
rb-inotify (0.9.2)
|
||||
ffi (>= 0.5.0)
|
||||
rb-kqueue (0.2.0)
|
||||
ffi (>= 0.5.0)
|
||||
redcarpet (2.3.0)
|
||||
safe_yaml (0.9.7)
|
||||
sanitize (2.0.6)
|
||||
nokogiri (>= 1.4.4)
|
||||
sass (3.2.12)
|
||||
syntax (1.0.0)
|
||||
yajl-ruby (1.1.0)
|
||||
|
||||
@@ -39,8 +52,10 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
jekyll (~> 1.0)
|
||||
jekyll (~> 1.3.0)
|
||||
json
|
||||
rake
|
||||
rb-fsevent
|
||||
redcarpet
|
||||
sanitize
|
||||
sass
|
||||
|
||||
@@ -21,6 +21,7 @@ Once you have RubyGems and installed Bundler (via `gem install bundler`), use it
|
||||
```sh
|
||||
$ cd react/docs
|
||||
$ bundle install # Might need sudo.
|
||||
$ npm install # Might need sudo.
|
||||
```
|
||||
|
||||
### Instructions
|
||||
|
||||
@@ -13,7 +13,7 @@ task :js do
|
||||
end
|
||||
|
||||
desc "watch css & js"
|
||||
task :watch => [:update_version] do
|
||||
task :watch do
|
||||
Process.spawn "sass --style=compressed --watch _css/react.scss:css/react.css"
|
||||
Process.spawn "../bin/jsx --watch _js js"
|
||||
Process.waitall
|
||||
@@ -30,8 +30,8 @@ task :update_version do
|
||||
end
|
||||
|
||||
desc "build into ../../react-gh-pages"
|
||||
task :release => [:default] do
|
||||
task :release => [:update_version, :default] do
|
||||
system "jekyll build -d ../../react-gh-pages"
|
||||
end
|
||||
|
||||
task :default => [:update_version, :css, :js]
|
||||
task :default => [:css, :js]
|
||||
|
||||
@@ -13,41 +13,8 @@ redcarpet:
|
||||
pygments: true
|
||||
name: React
|
||||
markdown: redcarpet
|
||||
react_version: 0.4.0
|
||||
react_version: 0.5.2
|
||||
description: A JavaScript library for building user interfaces
|
||||
relative_permalinks: true
|
||||
nav_docs_sections:
|
||||
- title: Quick Start
|
||||
items:
|
||||
- id: getting-started
|
||||
title: Getting Started
|
||||
- id: tutorial
|
||||
title: Tutorial
|
||||
- title: Guides
|
||||
items:
|
||||
- id: why-react
|
||||
title: Why React?
|
||||
- id: displaying-data
|
||||
title: Displaying Data
|
||||
subitems:
|
||||
- id: jsx-in-depth
|
||||
title: JSX in Depth
|
||||
- id: jsx-gotchas
|
||||
title: JSX Gotchas
|
||||
- id: interactivity-and-dynamic-uis
|
||||
title: Interactivity and Dynamic UIs
|
||||
- id: multiple-components
|
||||
title: Multiple Components
|
||||
- id: reusable-components
|
||||
title: Reusable Components
|
||||
- id: forms
|
||||
title: Forms
|
||||
- id: working-with-the-browser
|
||||
title: Working With the Browser
|
||||
subitems:
|
||||
- id: more-about-refs
|
||||
title: More About Refs
|
||||
- id: tooling-integration
|
||||
title: Tooling integration
|
||||
- id: reference
|
||||
title: Reference
|
||||
paginate: 5
|
||||
paginate_path: /blog/page:num/
|
||||
|
||||
@@ -15,6 +15,7 @@ $contentPadding: 20px;
|
||||
$columnWidth: 280px;
|
||||
$columnGutter: 40px;
|
||||
$twoColumnWidth: 2 * $columnWidth + $columnGutter;
|
||||
$navHeight: 50px;
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ html {
|
||||
|
||||
|
||||
.container {
|
||||
padding-top: 50px;
|
||||
padding-top: $navHeight;
|
||||
min-width: $contentWidth + (2 * $contentPadding);
|
||||
}
|
||||
|
||||
@@ -73,6 +74,23 @@ li {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
// Make header navigation linkable and on the screen. Used in documentation and
|
||||
// blog posts.
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
.anchor {
|
||||
margin-top: -$navHeight;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
&:hover .hash-link {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
.hash-link {
|
||||
color: $mediumTextColor;
|
||||
display: none;
|
||||
}
|
||||
|
||||
// Main Nav
|
||||
|
||||
.nav-main {
|
||||
@@ -81,7 +99,7 @@ li {
|
||||
color: $lightTextColor;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
height: 50px;
|
||||
height: $navHeight;
|
||||
box-shadow: 0 0 5px rgba(0, 0, 0, .5);
|
||||
width: 100%;
|
||||
z-index: 100;
|
||||
@@ -103,9 +121,9 @@ li {
|
||||
padding: 0 8px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
line-height: 50px;
|
||||
line-height: $navHeight;
|
||||
display: inline-block;
|
||||
height: 50px;
|
||||
height: $navHeight;
|
||||
color: $mediumTextColor;
|
||||
|
||||
&:hover {
|
||||
@@ -123,7 +141,7 @@ li {
|
||||
.nav-home {
|
||||
color: #00d8ff;
|
||||
font-size: 24px;
|
||||
line-height: 50px;
|
||||
line-height: $navHeight;
|
||||
}
|
||||
|
||||
.nav-logo {
|
||||
@@ -199,8 +217,7 @@ li {
|
||||
font-size: 14px;
|
||||
// position: fixed;
|
||||
float: left;
|
||||
top: 100px;
|
||||
width: 180px;
|
||||
width: 210px;
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
@@ -248,6 +265,12 @@ li {
|
||||
|
||||
}
|
||||
|
||||
.nav-blog {
|
||||
li {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
// Home Page specifics
|
||||
|
||||
.home-section {
|
||||
@@ -285,14 +308,14 @@ li {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
#examples {
|
||||
h3 {
|
||||
color: $darkColor;
|
||||
font-size: 24px;
|
||||
font-weight: normal;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#examples h3, .home-presentation h3 {
|
||||
color: $darkColor;
|
||||
font-size: 24px;
|
||||
font-weight: normal;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
#examples {
|
||||
p {
|
||||
margin: 0 0 25px 0;
|
||||
max-width: $twoColumnWidth;
|
||||
@@ -364,6 +387,8 @@ section.black content {
|
||||
*/
|
||||
|
||||
.blogContent {
|
||||
@include clearfix;
|
||||
|
||||
padding-top: 20px;
|
||||
|
||||
blockquote {
|
||||
@@ -386,6 +411,7 @@ section.black content {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
|
||||
// H2s form documentation topic dividers. Extra space helps.
|
||||
h2 {
|
||||
margin-top: 30px;
|
||||
@@ -433,7 +459,7 @@ section.black content {
|
||||
}
|
||||
|
||||
.playgroundPreview {
|
||||
padding: 14px;
|
||||
padding: 0;
|
||||
width: 600px;
|
||||
|
||||
pre {
|
||||
@@ -685,3 +711,15 @@ p code {
|
||||
.post {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-bottom: 30px;
|
||||
|
||||
/* Trick to get the wrapper to expand to fit floating elements */
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.next {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
57
docs/_data/nav_docs.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
- title: Quick Start
|
||||
items:
|
||||
- id: getting-started
|
||||
title: Getting Started
|
||||
- id: tutorial
|
||||
title: Tutorial
|
||||
- title: Guides
|
||||
items:
|
||||
- id: why-react
|
||||
title: Why React?
|
||||
- id: displaying-data
|
||||
title: Displaying Data
|
||||
subitems:
|
||||
- id: jsx-in-depth
|
||||
title: JSX in Depth
|
||||
- id: jsx-gotchas
|
||||
title: JSX Gotchas
|
||||
- id: interactivity-and-dynamic-uis
|
||||
title: Interactivity and Dynamic UIs
|
||||
- id: multiple-components
|
||||
title: Multiple Components
|
||||
- id: reusable-components
|
||||
title: Reusable Components
|
||||
- id: forms
|
||||
title: Forms
|
||||
- id: working-with-the-browser
|
||||
title: Working With the Browser
|
||||
subitems:
|
||||
- id: more-about-refs
|
||||
title: More About Refs
|
||||
- id: tooling-integration
|
||||
title: Tooling Integration
|
||||
- id: addons
|
||||
title: Add-Ons
|
||||
subitems:
|
||||
- id: animation
|
||||
title: Animation
|
||||
- id: two-way-binding-helpers
|
||||
title: Two-Way Binding Helpers
|
||||
- id: class-name-manipulation
|
||||
title: Class Name Manipulation
|
||||
- id: examples
|
||||
title: Examples
|
||||
- title: Reference
|
||||
items:
|
||||
- id: top-level-api
|
||||
title: Top-Level API
|
||||
- id: component-api
|
||||
title: Component API
|
||||
- id: component-specs
|
||||
title: Component Specs and Lifecycle
|
||||
- id: tags-and-attributes
|
||||
title: Supported Tags and Attributes
|
||||
- id: events
|
||||
title: Event System
|
||||
- id: dom-differences
|
||||
title: DOM Differences
|
||||
30
docs/_data/nav_tips.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
- title: Tips
|
||||
items:
|
||||
- id: introduction
|
||||
title: Introduction
|
||||
- id: inline-styles
|
||||
title: Inline Styles
|
||||
- id: if-else-in-JSX
|
||||
title: If-Else in JSX
|
||||
- id: self-closing-tag
|
||||
title: Self-Closing Tag
|
||||
- id: maximum-number-of-jsx-root-nodes
|
||||
title: Maximum Number of JSX Root Nodes
|
||||
- id: style-props-value-px
|
||||
title: Shorthand for Specifying Pixel Values in style props
|
||||
- id: children-props-type
|
||||
title: Type of the Children props
|
||||
- id: controlled-input-null-value
|
||||
title: Value of null for Controlled Input
|
||||
- id: componentWillReceiveProps-not-triggered-after-mounting
|
||||
title: componentWillReceiveProps Not Triggered After Mounting
|
||||
- id: props-in-getInitialState-as-anti-pattern
|
||||
title: Props in getInitialState Is an Anti-Pattern
|
||||
- id: dom-event-listeners
|
||||
title: DOM Event Listeners in a Component
|
||||
- id: initial-ajax
|
||||
title: Load Initial Data via AJAX
|
||||
- id: false-in-jsx
|
||||
title: False in JSX
|
||||
- id: communicate-between-components
|
||||
title: Communicate Between Components
|
||||
@@ -1,10 +1,11 @@
|
||||
<div class="nav-docs">
|
||||
<div class="nav-docs nav-blog">
|
||||
<div class="nav-docs-section">
|
||||
<h3>Recent posts</h3>
|
||||
<ul>
|
||||
{% for post in site.posts %}
|
||||
<li><a href="/react{{ post.url }}"{% if page.title == post.title %} class="active"{% endif %}>{{ post.title }}</a></li>
|
||||
{% endfor %}
|
||||
{% for post in site.posts limit:10 %}
|
||||
<li><a href="/react{{ post.url }}"{% if page.title == post.title %} class="active"{% endif %}>{{ post.title }}</a></li>
|
||||
{% endfor %}
|
||||
<li><a href="/react/blog/all.html">All posts ...</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<div class="nav-docs">
|
||||
{% for section in site.nav_docs_sections %}
|
||||
<!-- Docs Nav -->
|
||||
{% for section in site.data.nav_docs %}
|
||||
<div class="nav-docs-section">
|
||||
<h3>{{ section.title }}</h3>
|
||||
<ul>
|
||||
@@ -24,4 +25,18 @@
|
||||
</ul>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<!-- Tips Nav -->
|
||||
{% for section in site.data.nav_tips %}
|
||||
<div class="nav-docs-section">
|
||||
<h3>{{ section.title }}</h3>
|
||||
<ul>
|
||||
{% for item in section.items %}
|
||||
<li>
|
||||
<a href="/react/tips/{{ item.id }}.html"{% if page.id == item.id %} class="active"{% endif %}>{{ item.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
@@ -11,16 +11,17 @@ var MarkdownEditor = React.createClass({\n\
|
||||
getInitialState: function() {\n\
|
||||
return {value: 'Type some *markdown* here!'};\n\
|
||||
},\n\
|
||||
handleInput: function() {\n\
|
||||
handleChange: function() {\n\
|
||||
this.setState({value: this.refs.textarea.getDOMNode().value});\n\
|
||||
},\n\
|
||||
render: function() {\n\
|
||||
return (\n\
|
||||
<div className=\"MarkdownEditor\">\n\
|
||||
<h3>Input</h3>\n\
|
||||
<textarea onInput={this.handleInput} ref=\"textarea\">\n\
|
||||
{this.state.value}\n\
|
||||
</textarea>\n\
|
||||
<textarea\n\
|
||||
onChange={this.handleChange}\n\
|
||||
ref=\"textarea\"\n\
|
||||
defaultValue={this.state.value} />\n\
|
||||
<h3>Output</h3>\n\
|
||||
<div\n\
|
||||
className=\"content\"\n\
|
||||
|
||||
@@ -11,11 +11,14 @@ var Timer = React.createClass({\n\
|
||||
this.setState({secondsElapsed: this.state.secondsElapsed + 1});\n\
|
||||
},\n\
|
||||
componentDidMount: function() {\n\
|
||||
setInterval(this.tick, 1000);\n\
|
||||
this.interval = setInterval(this.tick, 1000);\n\
|
||||
},\n\
|
||||
componentWillUnmount: function() {\n\
|
||||
clearInterval(this.interval);\n\
|
||||
},\n\
|
||||
render: function() {\n\
|
||||
return React.DOM.div({},\n\
|
||||
'Seconds Elapsed: ' + this.state.secondsElapsed\n\
|
||||
'Seconds Elapsed: ', this.state.secondsElapsed\n\
|
||||
);\n\
|
||||
}\n\
|
||||
});\n\
|
||||
|
||||
@@ -16,7 +16,7 @@ var TodoApp = React.createClass({\n\
|
||||
getInitialState: function() {\n\
|
||||
return {items: [], text: ''};\n\
|
||||
},\n\
|
||||
onKey: function(e) {\n\
|
||||
onChange: function(e) {\n\
|
||||
this.setState({text: e.target.value});\n\
|
||||
},\n\
|
||||
handleSubmit: function(e) {\n\
|
||||
@@ -30,8 +30,8 @@ var TodoApp = React.createClass({\n\
|
||||
<div>\n\
|
||||
<h3>TODO</h3>\n\
|
||||
<TodoList items={this.state.items} />\n\
|
||||
<form onSubmit={this.handleSubmit.bind(this)}>\n\
|
||||
<input onKeyUp={this.onKey.bind(this)} value={this.state.text} />\n\
|
||||
<form onSubmit={this.handleSubmit}>\n\
|
||||
<input onChange={this.onChange} value={this.state.text} />\n\
|
||||
<button>{'Add #' + (this.state.items.length + 1)}</button>\n\
|
||||
</form>\n\
|
||||
</div>\n\
|
||||
|
||||
@@ -22,9 +22,10 @@ var CodeMirrorEditor = React.createClass({
|
||||
mode: 'javascript',
|
||||
lineNumbers: false,
|
||||
matchBrackets: true,
|
||||
theme: 'solarized-light'
|
||||
theme: 'solarized-light',
|
||||
readOnly: this.props.readOnly
|
||||
});
|
||||
this.editor.on('change', this.onChange.bind(this));
|
||||
this.editor.on('change', this.onChange);
|
||||
this.onChange();
|
||||
},
|
||||
onChange: function() {
|
||||
@@ -40,11 +41,11 @@ var CodeMirrorEditor = React.createClass({
|
||||
if (IS_MOBILE) {
|
||||
editor = <pre style={{overflow: 'scroll'}}>{this.props.codeText}</pre>;
|
||||
} else {
|
||||
editor = <textarea ref="editor">{this.props.codeText}</textarea>;
|
||||
editor = <textarea ref="editor" defaultValue={this.props.codeText} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={this.props.className}>
|
||||
<div className={this.props.className}>
|
||||
{editor}
|
||||
</div>
|
||||
);
|
||||
@@ -76,22 +77,22 @@ var ReactPlayground = React.createClass({
|
||||
content =
|
||||
<CodeMirrorEditor
|
||||
onChange={this.bindState('code')}
|
||||
class="playgroundStage"
|
||||
className="playgroundStage"
|
||||
codeText={this.state.code}
|
||||
/>;
|
||||
} else if (this.state.mode === this.MODES.JS) {
|
||||
content =
|
||||
<div class="playgroundJS playgroundStage">
|
||||
{this.getDesugaredCode()}
|
||||
<div className="playgroundJS playgroundStage">
|
||||
{this.getDesugaredCode()}
|
||||
</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="playground">
|
||||
<div class="playgroundCode">
|
||||
<div className="playground">
|
||||
<div className="playgroundCode">
|
||||
{content}
|
||||
</div>
|
||||
<div class="playgroundPreview">
|
||||
<div className="playgroundPreview">
|
||||
<div ref="mount" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -111,17 +112,18 @@ var ReactPlayground = React.createClass({
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
var desugaredCode = this.getDesugaredCode();
|
||||
if (this.props.renderCode) {
|
||||
React.renderComponent(
|
||||
<pre>{this.getDesugaredCode()}</pre>,
|
||||
<CodeMirrorEditor codeText={desugaredCode} readOnly={true} />,
|
||||
mountNode
|
||||
);
|
||||
} else {
|
||||
eval(this.getDesugaredCode());
|
||||
eval(desugaredCode);
|
||||
}
|
||||
} catch (e) {
|
||||
React.renderComponent(
|
||||
<div content={e.toString()} class="playgroundError" />,
|
||||
<div content={e.toString()} className="playgroundError" />,
|
||||
mountNode
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<meta property="og:url" content="http://facebook.github.io/react{{ page.url }}" />
|
||||
<meta property="og:image" content="http://facebook.github.io/react/img/logo_og.png" />
|
||||
<meta property="og:description" content="A JavaScript library for building user interfaces" />
|
||||
<meta property="fb:app_id" content="623268441017527" />
|
||||
|
||||
<link rel="shortcut icon" href="/react/favicon.ico">
|
||||
<link rel="alternate" type="application/rss+xml" title="{{ site.name }}" href="{{ site.url }}{{ site.baseurl }}/feed.xml">
|
||||
@@ -73,6 +74,7 @@
|
||||
</footer>
|
||||
</div>
|
||||
<div id="fb-root"></div>
|
||||
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
|
||||
6
docs/_layouts/redirect.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; {{ page.destination }}">
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
25
docs/_layouts/tips.html
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
layout: default
|
||||
sectionid: tips
|
||||
---
|
||||
|
||||
<section class="content wrap documentationContent">
|
||||
{% include nav_docs.html %}
|
||||
|
||||
<div class="inner-content">
|
||||
<h1>{{ page.title }}</h1>
|
||||
<div class="subHeader">{{ page.description }}</div>
|
||||
{{ content }}
|
||||
|
||||
<div class="docs-prevnext">
|
||||
{% if page.prev %}
|
||||
<a class="docs-prev" href="/react/tips/{{ page.prev }}">← Prev</a>
|
||||
{% endif %}
|
||||
{% if page.next %}
|
||||
<a class="docs-next" href="/react/tips/{{ page.next }}">Next →</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="fb-comments" data-width="650" data-num-posts="10" data-href="{{ site.url }}{{ site.baseurl }}{{ page.url }}"></div>
|
||||
</div>
|
||||
</section>
|
||||
17
docs/_plugins/header_links.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'redcarpet'
|
||||
require 'sanitize'
|
||||
|
||||
# Simple converter that is probably better than RedCarpet's built in TOC id
|
||||
# generator (which ends up with things lik id="toc_1"... terrible).
|
||||
|
||||
class Redcarpet::Render::HTML
|
||||
def header(title, level)
|
||||
clean_title = Sanitize.clean(title)
|
||||
.downcase
|
||||
.gsub(/\s+/, "-")
|
||||
.gsub(/[^A-Za-z0-9\-_.]/, "")
|
||||
|
||||
return "<h#{level}><a class=\"anchor\" name=\"#{clean_title}\"></a>#{title} <a class=\"hash-link\" href=\"##{clean_title}\">#</a></h#{level}>"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,8 +20,8 @@ These templates dictate the full set of abstractions that you are allowed to use
|
||||
to build your UI.
|
||||
|
||||
React approaches building user interfaces differently by breaking them into
|
||||
**components**. This means React uses JavaScript to generate markup, which we
|
||||
see as an advantage over templates for a few reasons:
|
||||
**components**. This means React uses a real, full featured programming language
|
||||
to render views, which we see as an advantage over templates for a few reasons:
|
||||
|
||||
- **JavaScript is a flexible, powerful programming language** with the ability
|
||||
to build abstractions. This is incredibly important in large applications.
|
||||
|
||||
@@ -8,7 +8,7 @@ The highlight of this week is that an interaction-heavy app has been ported to R
|
||||
|
||||
## Moving From Backbone To React
|
||||
|
||||
[Clay Allsopp](http://twitter.com/clayallsopp) successfuly ported [Propeller](http://usepropeller.com/blog/posts/from-backbone-to-react/), a fairly big, interaction-heavy JavaScript app, to React.
|
||||
[Clay Allsopp](http://twitter.com/clayallsopp) successfully ported [Propeller](http://usepropeller.com/blog/posts/from-backbone-to-react/), a fairly big, interaction-heavy JavaScript app, to React.
|
||||
|
||||
> [<img style="float: right; margin: 0 0 10px 10px;" src="/react/img/blog/propeller-logo.png" />](http://usepropeller.com/blog/posts/from-backbone-to-react/)Subviews involve a lot of easy-to-forget boilerplate that Backbone (by design) doesn't automate. Libraries like Backbone.Marionette offer more abstractions to make view nesting easier, but they're all limited by the fact that Backbone delegates how and went view-document attachment occurs to the application code.
|
||||
>
|
||||
|
||||
@@ -23,7 +23,7 @@ The best part is the demo of how React reconciliation process makes live editing
|
||||
|
||||
## React Snippets
|
||||
|
||||
Over the past several weeks, members of our team, [Pete Hunt](http://www.petehunt.net/) and [Paul O'Shannessy](http://zpao.com/), answered many questions that were asked in the [React group](https://groups.google.com/forum/#!forum/reactjs). They give a good overview of how to integrate React with other libraries and APIs through the use of [Mixins](/react/docs/mixins.html) and [Lifecycle Methods](/react/docs/advanced-components.html).
|
||||
Over the past several weeks, members of our team, [Pete Hunt](http://www.petehunt.net/) and [Paul O'Shannessy](http://zpao.com/), answered many questions that were asked in the [React group](https://groups.google.com/forum/#!forum/reactjs). They give a good overview of how to integrate React with other libraries and APIs through the use of [Mixins](/react/docs/reusable-components.html) and [Lifecycle Methods](/react/docs/working-with-the-browser.html).
|
||||
|
||||
> [Listening Scroll Event](https://groups.google.com/forum/#!topic/reactjs/l6PnP8qbofk)
|
||||
>
|
||||
|
||||
@@ -4,7 +4,7 @@ layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
Over the past 2 months we've been taking feedback and working hard to make React even better. We've also added several features that awe didn't finish in time for the v0.3 launch, and are proud to announce the availability of React v0.4 today!
|
||||
Over the past 2 months we've been taking feedback and working hard to make React even better. We fixed some bugs, made some under-the-hood improvements, and added several features that we think will improve the experience developing with React. Today we're proud to announce the availability of React v0.4!
|
||||
|
||||
|
||||
This release could not have happened without the support of our growing community. Since launch day, the community has contributed blog posts, questions to the [Google Group](http://groups.google.com/group/reactjs), and issues and pull requests on GitHub. We've had contributions ranging from documentation improvements to major changes to React's rendering. We've seen people integrate React into the tools they're using and the products they're building, and we're all very excited to see what our budding community builds next!
|
||||
@@ -24,13 +24,13 @@ When you're ready, [go download it](/react/downloads.html)!
|
||||
* Removed `React.autoBind`. [Read our blog post for details...](http://facebook.github.io/react/blog/2013/07/02/react-v0-4-autobind-by-default.html)
|
||||
* Improvements to forms. We've written wrappers around `<input>`, `<textarea>`, `<option>`, and `<select>` in order to standardize many inconsistencies in browser implementations. This includes support for `defaultValue`, and improved implementation of the `onChange` event, and circuit completion. [Read the docs for details...](http://facebook.github.io/react/docs/forms.html)
|
||||
* We've implemented an improved synthetic event system that conforms to the W3C spec.
|
||||
* Updates to your component are batched now, which may result in a significantly faster re-render of components. `this.setState` now takes an optional callback as it's second parameter. If you were using `onClick={this.setState.bind(this, state)}` previously, you'll want to make sure you add a third parameter so that the event is not treated as the callback.
|
||||
* Updates to your component are batched now, which may result in a significantly faster re-render of components. `this.setState` now takes an optional callback as its second parameter. If you were using `onClick={this.setState.bind(this, state)}` previously, you'll want to make sure you add a third parameter so that the event is not treated as the callback.
|
||||
|
||||
### JSX
|
||||
|
||||
* Support for comment nodes `<div>{/* this is a comment and won't be rendered */}</div>`
|
||||
* Children are now transformed directly into arguments instead of being wrapped in an array
|
||||
E.g. `<div><Component1/><Component2></div>` is transformed into `React.DOM.div(null, Component1(null), Component2(null))`.
|
||||
E.g. `<div><Component1/><Component2/></div>` is transformed into `React.DOM.div(null, Component1(null), Component2(null))`.
|
||||
Previously this would be transformed into `React.DOM.div(null, [Component1(null), Component2(null)])`.
|
||||
If you were using React without JSX previously, your code should still work.
|
||||
|
||||
|
||||
99
docs/_posts/2013-07-23-community-roundup-5.md
Normal file
@@ -0,0 +1,99 @@
|
||||
---
|
||||
title: "Community Round-up #5"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
We launched the [React Facebook Page](https://www.facebook.com/react) along with the React v0.4 launch. 700 people already liked it to get updated on the project :)
|
||||
|
||||
## Cross-browser onChange
|
||||
|
||||
[Ben Alpert](http://benalpert.com/) from [Khan Academy](https://www.khanacademy.org/) worked on a cross-browser implementation of `onChange` event that landed in v0.4. He wrote a blog post explaining the various browser quirks he had to deal with.
|
||||
|
||||
> First off, what is the input event? If you have an `<input>` element and want to receive events whenever the value changes, the most obvious thing to do is to listen to the change event. Unfortunately, change fires only after the text field is defocused, rather than on each keystroke. The next obvious choice is the keyup event, which is triggered whenever a key is released. Unfortunately, keyup doesn't catch input that doesn't involve the keyboard (e.g., pasting from the clipboard using the mouse) and only fires once if a key is held down, rather than once per inserted character.
|
||||
>
|
||||
> Both keydown and keypress do fire repeatedly when a key is held down, but both fire immediately before the value changes, so to read the new value you have to defer the handler to the next event loop using `setTimeout(fn, 0)` or similar, which slows down your app. Of course, like keyup, neither keydown nor keypress fires for non-keyboard input events, and all three can fire in cases where the value doesn't change at all (such as when pressing the arrow keys).
|
||||
>
|
||||
> [Read the full post...](http://benalpert.com/2013/06/18/a-near-perfect-oninput-shim-for-ie-8-and-9.html)
|
||||
|
||||
|
||||
## React Samples
|
||||
|
||||
Learning a new library is always easier when you have working examples you can play with. [jwh](https://github.com/jhw) put many of them on his [react-samples Github repo](https://github.com/jhw/react-samples).
|
||||
|
||||
> Some simple examples with Facebook's React framework
|
||||
>
|
||||
> * Bootstrap action bar, modal and table [#1](https://rawgithub.com/jhw/react-samples/master/html/actionbar.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/bootstrap_actionbar.html),
|
||||
> [#3](https://rawgithub.com/jhw/react-samples/master/html/bootstrap_modal.html),
|
||||
> [#4](https://rawgithub.com/jhw/react-samples/master/html/bootstrap_striped_table.html)
|
||||
> * Comments [#1](https://rawgithub.com/jhw/react-samples/master/html/comments1.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/comments2.html)
|
||||
> * Data Table [#1](https://rawgithub.com/jhw/react-samples/master/html/datatable.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/datatable2.html),
|
||||
> [#3](https://rawgithub.com/jhw/react-samples/master/html/datatable3.html),
|
||||
> [#4](https://rawgithub.com/jhw/react-samples/master/html/datatable4.html),
|
||||
> [#5](https://rawgithub.com/jhw/react-samples/master/html/datatable5.html)
|
||||
> * Filter Bar [#1](https://rawgithub.com/jhw/react-samples/master/html/filterbar.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/filterbar2.html),
|
||||
> [#3](https://rawgithub.com/jhw/react-samples/master/html/filterbar3.html),
|
||||
> [#4](https://rawgithub.com/jhw/react-samples/master/html/filterbar4.html),
|
||||
> [#5](https://rawgithub.com/jhw/react-samples/master/html/filterbar5.html)
|
||||
> * Fundoo Rating [#1](https://rawgithub.com/jhw/react-samples/master/html/fundoo.html)
|
||||
> * Line Char: [#1](https://rawgithub.com/jhw/react-samples/master/html/linechart.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/linechart2.html)
|
||||
> * Multi tabs [#1](https://rawgithub.com/jhw/react-samples/master/html/multitabs.html)
|
||||
> * Select [#1](https://rawgithub.com/jhw/react-samples/master/html/select.html)
|
||||
> * Simple Tabs [#1](https://rawgithub.com/jhw/react-samples/master/html/simpletabs.html),
|
||||
> [#2](https://rawgithub.com/jhw/react-samples/master/html/simpletabs2.html),
|
||||
> [#3](https://rawgithub.com/jhw/react-samples/master/html/simpletabs3.html),
|
||||
> [#4](https://rawgithub.com/jhw/react-samples/master/html/simpletabs4.html)
|
||||
> * Toggle [#1](https://rawgithub.com/jhw/react-samples/master/html/toggle.html)
|
||||
|
||||
|
||||
## React Chosen Wrapper
|
||||
|
||||
[Cheng Lou](https://github.com/chenglou) wrote a wrapper for the [Chosen](http://harvesthq.github.io/chosen/) input library called [react-chosen](https://github.com/chenglou/react-chosen). It took just 25 lines to be able to use jQuery component as a React one.
|
||||
|
||||
```javascript
|
||||
React.renderComponent(
|
||||
<Chosen noResultsText="No result" value="Harvest" onChange={doSomething}>
|
||||
<option value="Facebook">Facebook</option>
|
||||
<option value="Harvest">Harvest</option>
|
||||
</Chosen>
|
||||
, document.body);
|
||||
```
|
||||
|
||||
|
||||
## JSX and ES6 Template Strings
|
||||
|
||||
[Domenic Denicola](http://domenicdenicola.com/) wrote a slide deck about the great applications of ES6 features and one slide shows how we could use Template Strings to compile JSX at run-time without the need for a pre-processing phase.
|
||||
|
||||
<figure><iframe src="http://www.slideshare.net/slideshow/embed_code/24187146?rel=0&startSlide=36" width="600" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe></figure>
|
||||
|
||||
|
||||
## React Presentation
|
||||
|
||||
[Tom Occhino](http://tomocchino.com/) and [Jordan Walke](https://github.com/jordwalke), React developers, did a presentation of React at Facebook Seattle's office. Check out the first 25 minutes for the presentation and the remaining 45 for a Q&A. I highly recommend you watching this video.
|
||||
|
||||
<figure><iframe width="650" height="400" src="//www.youtube.com/embed/XxVg_s8xAms" frameborder="0" allowfullscreen></iframe></figure>
|
||||
|
||||
|
||||
## Docs
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/) rewrote the entirety of the docs for v0.4. The goal was to add more explanation about why we built React and what the best practices are.
|
||||
|
||||
> Guides
|
||||
>
|
||||
> * [Why React?](/react/docs/why-react.html)
|
||||
> * [Displaying Data](/react/docs/displaying-data.html)
|
||||
> * [JSX in Depth](/react/docs/jsx-in-depth.html)
|
||||
> * [JSX Gotchas](/react/docs/jsx-gotchas.html)
|
||||
> * [Interactivity and Dynamic UIs](/react/docs/interactivity-and-dynamic-uis.html)
|
||||
> * [Multiple Components](/react/docs/multiple-components.html)
|
||||
> * [Reusable Components](/react/docs/reusable-components.html)
|
||||
> * [Forms](/react/docs/forms.html)
|
||||
> * [Working With the Browser](/react/docs/working-with-the-browser.html)
|
||||
> * [More About Refs](/react/docs/more-about-refs.html)
|
||||
> * [Tooling integration](/react/docs/tooling-integration.html)
|
||||
> * [Reference](/react/docs/top-level-api.html)
|
||||
25
docs/_posts/2013-07-26-react-v0-4-1.md
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "React v0.4.1"
|
||||
layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
React v0.4.1 is a small update, mostly containing correctness fixes. Some code has been restructured internally but those changes do not impact any of our public APIs.
|
||||
|
||||
|
||||
## React
|
||||
|
||||
* `setState` callbacks are now executed in the scope of your component.
|
||||
* `click` events now work on Mobile Safari.
|
||||
* Prevent a potential error in event handling if `Object.prototype` is extended.
|
||||
* Don't set DOM attributes to the string `"undefined"` on update when previously defined.
|
||||
* Improved support for `<iframe>` attributes.
|
||||
* Added checksums to detect and correct cases where server-side rendering markup mismatches what React expects client-side.
|
||||
|
||||
|
||||
## JSXTransformer
|
||||
|
||||
* Improved environment detection so it can be run in a non-browser environment.
|
||||
|
||||
|
||||
[Download it now!](/react/downloads.html)
|
||||
54
docs/_posts/2013-07-30-use-react-and-jsx-in-ruby-on-rails.md
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
title: "Use React and JSX in Ruby on Rails"
|
||||
layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
Today we're releasing a gem to make it easier to use React and JSX in Ruby on Rails applications: [react-rails](https://github.com/facebook/react-rails).
|
||||
|
||||
|
||||
This gem has 2 primary purposes:
|
||||
|
||||
1. To package `react.js` in a way that's easy to use and easy to update.
|
||||
2. To allow you to write JSX without an external build step to transform that into JS.
|
||||
|
||||
|
||||
## Packaging react.js
|
||||
|
||||
To make `react.js` available for use client-side, simply add `react` to your manifest, and declare the variant you'd like to use in your environment. When you use `:production`, the minified and optimized `react.min.js` will be used instead of the development version. For example:
|
||||
|
||||
```ruby
|
||||
# config/environments/development.rb
|
||||
|
||||
MyApp::Application.configure do
|
||||
config.react.variant = :development
|
||||
# use :production in production.rb
|
||||
end
|
||||
```
|
||||
|
||||
```js
|
||||
// app/assets/javascript/application.js
|
||||
|
||||
//= require react
|
||||
```
|
||||
|
||||
|
||||
## Writing JSX
|
||||
|
||||
When you name your file with `myfile.js.jsx`, `react-rails` will automatically try to transform that file. For the time being, we still require that you include the docblock at the beginning of the file. For example, this file will get transformed on request.
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
React.renderComponent(<MyComponent/>, document.body)
|
||||
```
|
||||
|
||||
|
||||
## Asset Pipeline
|
||||
|
||||
`react-rails` takes advantage of the [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html) that was introduced in Rails 3.1. A very important part of that pipeline is the `assets:precompile` Rake task. `react-rails` will ensure that your JSX files will be transformed into regular JS before all of your assets are minified and packaged.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Installation follows the same process you're familiar with. You can install it globally with `gem install react-rails`, though we suggest you add the dependency to your `Gemfile` directly.
|
||||
|
||||
80
docs/_posts/2013-08-05-community-roundup-6.md
Normal file
@@ -0,0 +1,80 @@
|
||||
---
|
||||
title: "Community Round-up #6"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
This is the first Community Round-up where none of the items are from Facebook/Instagram employees. It's great to see the adoption of React growing.
|
||||
|
||||
## React Game Tutorial
|
||||
|
||||
[Caleb Cassel](https://twitter.com/CalebCassel) wrote a [step-by-step tutorial](https://rawgithub.com/calebcassel/react-demo/master/part1.html) about making a small game. It covers JSX, State and Events, Embedded Components and Integration with Backbone.
|
||||
<figure>[](https://rawgithub.com/calebcassel/react-demo/master/part1.html)</figure>
|
||||
|
||||
|
||||
## Reactify
|
||||
|
||||
[Andrey Popp](http://andreypopp.com/) created a [Browserify](http://browserify.org/) helper to compile JSX files.
|
||||
|
||||
> Browserify v2 transform for `text/jsx`. Basic usage is:
|
||||
>
|
||||
> ```
|
||||
% browserify -t reactify main.jsx
|
||||
```
|
||||
>
|
||||
> `reactify` transform activates for files with either `.jsx` extension or `/** @jsx React.DOM */` pragma as a first line for any `.js` file.
|
||||
>
|
||||
> [Check it out on Github...](https://github.com/andreypopp/reactify)
|
||||
|
||||
|
||||
|
||||
## React Integration with Este
|
||||
|
||||
[Daniel Steigerwald](http://daniel.steigerwald.cz/) is now using React within [Este](https://github.com/steida/este), which is a development stack for web apps in CoffeeScript that are statically typed using the Closure Library.
|
||||
|
||||
```coffeescript
|
||||
este.demos.react.todoApp = este.react.create (`/** @lends {React.ReactComponent.prototype} */`)
|
||||
render: ->
|
||||
@div [
|
||||
este.demos.react.todoList 'items': @state['items']
|
||||
if @state['items'].length
|
||||
@p "#{@state['items'].length} items."
|
||||
@form 'onSubmit': @onFormSubmit, [
|
||||
@input
|
||||
'onChange': @onChange
|
||||
'value': @state['text']
|
||||
'autoFocus': true
|
||||
'ref': 'textInput'
|
||||
@button "Add ##{@state['items'].length + 1}"
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
[Check it out on Github...](https://github.com/steida/este-library/blob/master/este/demos/thirdparty/react/start.coffee)
|
||||
|
||||
|
||||
## React Stylus Boilerplate
|
||||
|
||||
[Zaim Bakar](http://zaim.github.io/) shared his boilerplate to get started with Stylus CSS processor.
|
||||
|
||||
> This is my boilerplate React project using Grunt as the build tool, and Stylus as my CSS preprocessor.
|
||||
>
|
||||
> - Very minimal HTML boilerplate
|
||||
> - Uses Stylus, with nib included
|
||||
> - Uses two build targets:
|
||||
> - `grunt build` to compile JSX and Stylus into a development build
|
||||
> - `grunt dist` to minify and optimize the development build for production
|
||||
>
|
||||
> [Check it out on Github...](https://github.com/zaim/react-stylus-boilerplate)
|
||||
|
||||
|
||||
## WebFUI
|
||||
|
||||
[Conrad Barski](http://lisperati.com/), author of the popular book [Land of Lisp](http://landoflisp.com/), wants to use React for his ClojureScript library called [WebFUI](https://github.com/drcode/webfui).
|
||||
|
||||
> I'm the author of "[Land of Lisp](http://landoflisp.com/)" and I love your framework. I built a somewhat similar framework a year ago [WebFUI](https://github.com/drcode/webfui) aimed at ClojureScript. My framework also uses global event delegates, a global "render" function, DOM reconciliation, etc just like react.js. (Of course these ideas all have been floating around the ether for ages, always great to see more people building on them.)
|
||||
>
|
||||
> Your implementation is more robust, and so I think the next point release of webfui will simply delegate all the "hard work" to react.js and will only focus on the areas where it adds value (enabling purely functional UI programming in clojurescript, and some other stuff related to streamlining event handling)
|
||||
<figure>[](https://groups.google.com/forum/#!msg/reactjs/e3bYersyd64/qODfcuBR9LwJ)</figure>
|
||||
>
|
||||
> [Read the full post...](https://groups.google.com/forum/#!msg/reactjs/e3bYersyd64/qODfcuBR9LwJ)
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: "Use React and JSX in Python Applications"
|
||||
layout: post
|
||||
author: Kunal Mehta
|
||||
---
|
||||
|
||||
Today we're happy to announce the initial release of [PyReact](https://github.com/facebook/react-python), which makes it easier to use React and JSX in your Python applications. It's designed to provide an API to transform your JSX files into JavaScript, as well as provide access to the latest React source files.
|
||||
|
||||
## Usage
|
||||
|
||||
Transform your JSX files via the provided `jsx` module:
|
||||
|
||||
```python
|
||||
from react import jsx
|
||||
|
||||
# For multiple paths, use the JSXTransformer class.
|
||||
transformer = jsx.JSXTransformer()
|
||||
for jsx_path, js_path in my_paths:
|
||||
transformer.transform(jsx_path, js_path)
|
||||
|
||||
# For a single file, you can use a shortcut method.
|
||||
jsx.transform('path/to/input/file.jsx', 'path/to/output/file.js')
|
||||
```
|
||||
|
||||
For full paths to React files, use the `source` module:
|
||||
|
||||
```python
|
||||
from react import source
|
||||
|
||||
# path_for raises IOError if the file doesn't exist.
|
||||
react_js = source.path_for('react.min.js')
|
||||
```
|
||||
|
||||
## Django
|
||||
|
||||
PyReact includes a JSX compiler for [django-pipeline](https://github.com/cyberdelia/django-pipeline). Add it to your project's pipeline settings like this:
|
||||
|
||||
```python
|
||||
PIPELINE_COMPILERS = (
|
||||
'react.utils.pipeline.JSXCompiler',
|
||||
)
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
PyReact is hosted on PyPI, and can be installed with `pip`:
|
||||
|
||||
$ pip install PyReact
|
||||
|
||||
Alternatively, add it into your `requirements` file:
|
||||
|
||||
PyReact==0.1.1
|
||||
|
||||
**Dependencies**: PyReact uses [PyExecJS](https://github.com/doloopwhile/PyExecJS) to execute the bundled React code, which requires that a JS runtime environment is installed on your machine. We don't explicitly set a dependency on a runtime environment; Mac OS X comes bundled with one. If you're on a different platform, we recommend [PyV8](https://code.google.com/p/pyv8/).
|
||||
|
||||
For the initial release, we've only tested on Python 2.7. Look out for support for Python 3 in the future, and if you see anything that can be improved, we welcome your [contributions](https://github.com/facebook/react-python/blob/master/CONTRIBUTING.md)!
|
||||
74
docs/_posts/2013-08-26-community-roundup-7.md
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
title: "Community Round-up #7"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
It's been three months since we open sourced React and it is going well. Some stats so far:
|
||||
|
||||
* 114 285 unique visitors on this website
|
||||
* [1933 stars](https://github.com/facebook/react/stargazers) and [210 forks](https://github.com/facebook/react/network/members)
|
||||
* [226 posts on Google Group](https://groups.google.com/forum/#!forum/reactjs)
|
||||
* [76 Github projects using React](https://gist.github.com/vjeux/6335762)
|
||||
* [30 contributors](https://github.com/facebook/react/graphs/contributors)
|
||||
* [15 blog posts](http://facebook.github.io/react/blog/)
|
||||
* 2 early adopters: [Khan Academy](http://benalpert.com/2013/06/09/using-react-to-speed-up-khan-academy.html) and [Propeller](http://usepropeller.com/blog/posts/from-backbone-to-react/)
|
||||
|
||||
|
||||
## Wolfenstein Rendering Engine Ported to React
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/) ported the render code of the web version of Wolfenstein 3D to React. Check out [the demo](http://www.petehunt.net/wolfenstein3D-react/wolf3d.html) and [render.js](https://github.com/petehunt/wolfenstein3D-react/blob/master/js/renderer.js#L183) file for the implementation.
|
||||
<figure>[](http://www.petehunt.net/wolfenstein3D-react/wolf3d.html)</figure>
|
||||
|
||||
|
||||
## React & Meteor
|
||||
|
||||
[Ben Newman](https://twitter.com/benjamn) made a [13-lines wrapper](https://github.com/benjamn/meteor-react/blob/master/lib/mixin.js) to use React and Meteor together. [Meteor](http://www.meteor.com/) handles the real-time data synchronization between client and server. React provides the declarative way to write the interface and only updates the parts of the UI that changed.
|
||||
|
||||
> This repository defines a Meteor package that automatically integrates the React rendering framework on both the client and the server, to complement or replace the default Handlebars templating system.
|
||||
>
|
||||
> The React core is officially agnostic about how you fetch and update your data, so it is far from obvious which approach is the best. This package provides one answer to that question (use Meteor!), and I hope you will find it a compelling combination.
|
||||
>
|
||||
>```javascript
|
||||
>var MyComponent = React.createClass({
|
||||
> mixins: [MeteorMixin],
|
||||
>
|
||||
> getMeteorState: function() {
|
||||
> return { foo: Session.get('foo') };
|
||||
> },
|
||||
>
|
||||
> render: function() {
|
||||
> return <div>{this.state.foo}</div>;
|
||||
> }
|
||||
>});
|
||||
>```
|
||||
>
|
||||
> Dependencies will be registered for any data accesses performed by getMeteorState so that the component can be automatically re-rendered whenever the data changes.
|
||||
>
|
||||
> [Read more ...](https://github.com/benjamn/meteor-react)
|
||||
|
||||
## React Page
|
||||
|
||||
[Jordan Walke](https://github.com/jordwalke) implemented a complete React project creator called [react-page](https://github.com/facebook/react-page/). It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.
|
||||
|
||||
> Easy Application Development with React JavaScript
|
||||
> <figure>[](https://github.com/facebook/react-page/)</figure>
|
||||
>
|
||||
> **Why Server Rendering?**
|
||||
>
|
||||
> * Faster initial page speed:
|
||||
> * Markup displayed before downloading large JavaScript.
|
||||
> * Markup can be generated more quickly on a fast server than low power client devices.
|
||||
> * Faster Development and Prototyping:
|
||||
> * Instantly refresh your app without waiting for any watch scripts or bundlers.
|
||||
> * Easy deployment of static content pages/blogs: just archive using recursive wget.
|
||||
> * SEO benefits of indexability and perf.
|
||||
>
|
||||
> **How Does Server Rendering Work?**
|
||||
>
|
||||
> * `react-page` computes page markup on the server, sends it to the client so the user can see it quickly.
|
||||
> * The corresponding JavaScript is then packaged and sent.
|
||||
> * The browser runs that JavaScript, so that all of the event handlers, interactions and update code will run seamlessly on top of the server generated markup.
|
||||
> * From the developer's (and the user's) perspective, it's just as if the rendering occurred on the client, only faster.
|
||||
>
|
||||
> [Try it out ...](https://github.com/facebook/react-page/)
|
||||
70
docs/_posts/2013-09-24-community-roundup-8.md
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
title: "Community Round-up #8"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
A lot has happened in the month since our last update. Here are some of the more interesting things we've found. But first, we have a couple updates before we share links.
|
||||
|
||||
First, we are organizing a [React Hackathon](http://reactjshack-a-thon.splashthat.com/) in Facebook's Seattle office on Saturday September 28. If you want to hack on React, meet some of the team or win some prizes, feel free to join us!
|
||||
|
||||
We've also reached a point where there are too many questions for us to handle directly. We're encouraging people to ask questions on [StackOverflow](http://stackoverflow.com/questions/tagged/reactjs) using the tag [[reactjs]](http://stackoverflow.com/questions/tagged/reactjs). Many members of the team and community have subscribed to the tag, so feel free to ask questions there. We think these will be more discoverable than Google Groups archives or IRC logs.
|
||||
|
||||
## Javascript Jabber
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/) and [Jordan Walke](https://github.com/jordwalke) were interviewed on [Javascript Jabber](http://javascriptjabber.com/073-jsj-react-with-pete-hunt-and-jordan-walke/) for an hour. They go over many aspects of React such as 60 FPS, Data binding, Performance, Diffing Algorithm, DOM Manipulation, Node.js support, server-side rendering, JSX, requestAnimationFrame and the community. This is a gold mine of information about React.
|
||||
|
||||
> **PETE:** So React was designed all around that. Conceptually, how you build a React app is that every time your data changes, it's like hitting the refresh button in a server-rendered app. What we do is we conceptually throw out all of the markup and event handlers that you've registered and we reset the whole page and then we redraw the entire page. If you're writing a server-rendered app, handling updates is really easy because you hit the refresh button and you're pretty much guaranteed to get what you expect.
|
||||
>
|
||||
> **MERRICK:** That's true. You don't get into these odd states.
|
||||
>
|
||||
> **PETE:** Exactly, exactly. In order to implement that, we communicate it as a fake DOM. What we'll do is rather than throw out the actual browser html and event handlers, we have an internal representation of what the page looks like and then we generate a brand new representation of what we want the page to look like. Then we perform this really, really fast diffing algorithm between those two page representations, DOM representations. Then React will compute the minimum set of DOM mutations it needs to make to bring the page up to date.
|
||||
>
|
||||
> Then to finally get to answer your question, that set of DOM mutations then goes into a queue and we can plug in arbitrary flushing strategies for that. For example, when we originally launched React in open source, every setState would immediately trigger a flush to the DOM. That wasn't part of the contract of setState, but that was just our strategy and it worked pretty well. Then this totally awesome open source contributor Ben Alpert at Khan Academy built a new batching strategy which would basically queue up every single DOM update and state change that happened within an event tick and would execute them in bulk at the end of the event tick.
|
||||
>
|
||||
> [Read the full conversation ...](http://javascriptjabber.com/073-jsj-react-with-pete-hunt-and-jordan-walke/)
|
||||
|
||||
|
||||
## JSXTransformer Trick
|
||||
|
||||
While this is not going to work for all the attributes since they are camelCased in React, this is a pretty cool trick.
|
||||
|
||||
<div style="margin-left: 74px;"><blockquote class="twitter-tweet"><p>Turn any DOM element into a React.js function: JSXTransformer.transform("/** <a href="https://twitter.com/jsx">@jsx</a> React.DOM */" + element.innerHTML).code</p>— Ross Allen (@ssorallen) <a href="https://twitter.com/ssorallen/statuses/377105575441489920">September 9, 2013</a></blockquote></div>
|
||||
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
|
||||
|
||||
|
||||
## Remarkable React
|
||||
|
||||
[Stoyan Stefanov](http://www.phpied.com/) gave a talk at [BrazilJS](http://braziljs.com.br/) about React and wrote an article with the content of the presentation. He goes through the difficulties of writting _active apps_ using the DOM API and shows how React handles it.
|
||||
|
||||
> So how does exactly React deal with it internally? Two crazy ideas - virtual DOM and synthetic events.
|
||||
>
|
||||
> You define you components in React. It builds a virtual DOM in JavaScript land which is way more efficient. Then it updates the DOM. (And "virtual DOM" is a very big name for what is simply a JavaScript object with nested key-value pairs)
|
||||
>
|
||||
> Data changes. React computes a diff (in JavaScript land, which is, of course, much more efficient) and updates the single table cell that needs to change. React replicates the state of the virtual DOM into the actual DOM only when and where it's necessary. And does it all at once, in most cases in a single tick of the `requestAnimationFrame()`.
|
||||
>
|
||||
> What about event handlers? They are synthetic. React uses event delegation to listen way at the top of the React tree. So removing a node in the virtual DOM has no effect on the event handling.
|
||||
>
|
||||
> The events are automatically cross-browser (they are React events). They are also much closer to W3C than any browser. That means that for example `e.target` works, no need to look for the event object or checking whether it's `e.target` or `e.srcElement` (IE). Bubbling and capturing phases also work cross browser. React also takes the liberty of making some small fixes, e.g. the event `<input onChange>` fires when you type, not when blur away from the input. And of course, event delegation is used as the most efficient way to handle events. You know that "thou shall use event delegation" is also commonly given advice for making web apps snappy.
|
||||
>
|
||||
> The good thing about the virtual DOM is that it's all in JavaScript land. You build all your UI in JavaScript. Which means it can be rendered on the server side, so you initial view is fast (and any SEO concerns are addressed). Also, if there are especially heavy operations they can be threaded into WebWorkers, which otherwise have no DOM access.
|
||||
>
|
||||
> [Read More ...](http://www.phpied.com/remarkable-react/)
|
||||
|
||||
|
||||
## Markdown in React
|
||||
|
||||
[Ben Alpert](http://benalpert.com/) converted [marked](https://github.com/chjj/marked), a Markdown Javascript implementation, in React: [marked-react](https://github.com/spicyj/marked-react). Even without using JSX, the HTML generation is now a lot cleaner. It is also safer as forgetting a call to `escape` will not introduce an XSS vulnerability.
|
||||
<figure>[](https://github.com/spicyj/marked-react/commit/cb70c9df6542c7c34ede9efe16f9b6580692a457)</figure>
|
||||
|
||||
|
||||
## Unite from BugBusters
|
||||
|
||||
[Renault John Lecoultre](https://twitter.com/renajohn) wrote [Unite](https://www.bugbuster.com/), an interactive tool for analyzing code dynamically using React. It integrates with CodeMirror.
|
||||
<figure>[](https://unite.bugbuster.com/)</figure>
|
||||
|
||||
## #reactjs IRC Logs
|
||||
|
||||
[Vjeux](http://blog.vjeux.com/) re-implemented the display part of the IRC logger in React. Just 130 lines are needed for a performant infinite scroll with timestamps and color-coded author names.
|
||||
|
||||
<iframe width="100%" height="300" src="http://jsfiddle.net/vjeux/QL9tz/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
|
||||
52
docs/_posts/2013-10-16-react-v0.5.0.md
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: "React v0.5"
|
||||
layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
This release is the result of several months of hard work from members of the team and the community. While there are no groundbreaking changes in core, we've worked hard to improve performance and memory usage. We've also worked hard to make sure we are being consistent in our usage of DOM properties.
|
||||
|
||||
The biggest change you'll notice as a developer is that we no longer support `class` in JSX as a way to provide CSS classes. Since this prop was being converted to `className` at the transform step, it caused some confusion when trying to access it in composite components. As a result we decided to make our DOM properties mirror their counterparts in the JS DOM API. There are [a few exceptions](https://github.com/facebook/react/blob/master/src/dom/DefaultDOMPropertyConfig.js#L156) where we deviate slightly in an attempt to be consistent internally.
|
||||
|
||||
The other major change in v0.5 is that we've added an additional build - `react-with-addons` - which adds support for some extras that we've been working on including animations and two-way binding. [Read more about these addons in the docs](/react/docs/addons.html).
|
||||
|
||||
## Thanks to Our Community
|
||||
|
||||
We added *22 new people* to the list of authors since we launched React v0.4.1 nearly 3 months ago. With a total of 48 names in our `AUTHORS` file, that means we've nearly doubled the number of contributors in that time period. We've seen the number of people contributing to discussion on IRC, mailing lists, Stack Overflow, and GitHub continue rising. We've also had people tell us about talks they've given in their local community about React.
|
||||
|
||||
It's been awesome to see the things that people are building with React, and we can't wait to see what you come up with next!
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
### React
|
||||
|
||||
* Memory usage improvements - reduced allocations in core which will help with GC pauses
|
||||
* Performance improvements - in addition to speeding things up, we made some tweaks to stay out of slow path code in V8 and Nitro.
|
||||
* Standardized prop -> DOM attribute process. This previously resulting in additional type checking and overhead as well as confusing cases for users. Now we will always convert your value to a string before inserting it into the DOM.
|
||||
* Support for Selection events.
|
||||
* Support for [Composition events](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent).
|
||||
* Support for additional DOM properties (`charSet`, `content`, `form`, `httpEquiv`, `rowSpan`, `autoCapitalize`).
|
||||
* Support for additional SVG properties (`rx`, `ry`).
|
||||
* Support for using `getInitialState` and `getDefaultProps` in mixins.
|
||||
* Support mounting into iframes.
|
||||
* Bug fixes for controlled form components.
|
||||
* Bug fixes for SVG element creation.
|
||||
* Added `React.version`.
|
||||
* Added `React.isValidClass` - Used to determine if a value is a valid component constructor.
|
||||
* Removed `React.autoBind` - This was deprecated in v0.4 and now properly removed.
|
||||
* Renamed `React.unmountAndReleaseReactRootNode` to `React.unmountComponentAtNode`.
|
||||
* Began laying down work for refined performance analysis.
|
||||
* Better support for server-side rendering - [react-page](https://github.com/facebook/react-page) has helped improve the stability for server-side rendering.
|
||||
* Made it possible to use React in environments enforcing a strict [Content Security Policy](https://developer.mozilla.org/en-US/docs/Security/CSP/Introducing_Content_Security_Policy). This also makes it possible to use React to build Chrome extensions.
|
||||
|
||||
### React with Addons (New!)
|
||||
|
||||
* Introduced a separate build with several "addons" which we think can help improve the React experience. We plan to deprecate this in the long-term, instead shipping each as standalone pieces. [Read more in the docs](/react/docs/addons.html).
|
||||
|
||||
### JSX
|
||||
|
||||
* No longer transform `class` to `className` as part of the transform! This is a breaking change - if you were using `class`, you *must* change this to `className` or your components will be visually broken.
|
||||
* Added warnings to the in-browser transformer to make it clear it is not intended for production use.
|
||||
* Improved compatibility for Windows
|
||||
* Improved support for maintaining line numbers when transforming.
|
||||
25
docs/_posts/2013-10-29-react-v0-5-1.md
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: "React v0.5.1"
|
||||
layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
This release focuses on fixing some small bugs that have been uncovered over the past two weeks. I would like to thank everybody involved, specifically members of the community who fixed half of the issues found. Thanks to [Ben Alpert][1], [Andrey Popp][2], and [Laurence Rowe][3] for their contributions!
|
||||
|
||||
## Changelog
|
||||
|
||||
### React
|
||||
|
||||
* Fixed bug with `<input type="range">` and selection events.
|
||||
* Fixed bug with selection and focus.
|
||||
* Made it possible to unmount components from the document root.
|
||||
* Fixed bug for `disabled` attribute handling on non-`<input>` elements.
|
||||
|
||||
### React with Addons
|
||||
|
||||
* Fixed bug with transition and animation event detection.
|
||||
|
||||
[1]: https://github.com/spicyj
|
||||
[2]: https://github.com/andreypopp
|
||||
[3]: https://github.com/lrowe
|
||||
|
||||
100
docs/_posts/2013-10-3-community-roundup-9.md
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
title: "Community Round-up #9"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
We organized a React hackathon last week-end in the Facebook Seattle office. 50 people, grouped into 15 teams, came to hack for a day on React. It was a lot of fun and we'll probably organize more in the future.
|
||||
|
||||

|
||||
|
||||
|
||||
## React Hackathon Winner
|
||||
|
||||
[Alex Swan](http://bold-it.com/) implemented [Qu.izti.me](http://qu.izti.me/), a multi-player quiz game. It is real-time via Web Socket and mobile friendly.
|
||||
|
||||
> The game itself is pretty simple. People join the "room" by going to [http://qu.izti.me](http://qu.izti.me/) on their device. Large displays will show a leaderboard along with the game, and small displays (such as phones) will act as personal gamepads. Users will see questions and a choice of answers. The faster you answer, the more points you earn.
|
||||
>
|
||||
> In my opinion, Socket.io and React go together like chocolate and peanut butter. The page was always an accurate representation of the game object.
|
||||
><figure>[](http://bold-it.com/javascript/facebook-react-example/)</figure>
|
||||
>
|
||||
> [Read More...](http://bold-it.com/javascript/facebook-react-example/)
|
||||
|
||||
## JSConf EU Talk: Rethinking Best Practices
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/) presented React at JSConf EU. He covers three controversial design decisions of React:
|
||||
|
||||
1. Build **components**, not templates
|
||||
2. Re-render the whole app on every update
|
||||
3. Virtual DOM
|
||||
|
||||
The video will be available soon on the [JSConf EU website](http://2013.jsconf.eu/speakers/pete-hunt-react-rethinking-best-practices.html), but in the meantime, here are Pete's slides:
|
||||
|
||||
<figure><iframe src="http://www.slideshare.net/slideshow/embed_code/26589373" width="550" height="450" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen></iframe></figure>
|
||||
|
||||
|
||||
## Pump - Clojure bindings for React
|
||||
|
||||
[Alexander Solovyov](http://solovyov.net/) has been working on React bindings for ClojureScript. This is really exciting as it is using "native" ClojureScript data structures.
|
||||
|
||||
```ruby
|
||||
(ns your.app
|
||||
(:require-macros [pump.def-macros :refer [defr]])
|
||||
(:require [pump.core]))
|
||||
|
||||
(defr Component
|
||||
:get-initial-state #(identity {:some-value ""})
|
||||
|
||||
[component props state]
|
||||
|
||||
[:div {:class-name "test"} "hello"])
|
||||
```
|
||||
|
||||
[Check it out on GitHub...](https://github.com/piranha/pump)
|
||||
|
||||
|
||||
## JSXHint
|
||||
|
||||
[Todd Kennedy](http://blog.selfassembled.org/) working at [Condé Nast](http://www.condenast.com/) implemented a wrapper on-top of [JSHint](http://www.jshint.com/) that first converts JSX files to JS.
|
||||
|
||||
> A wrapper around JSHint to allow linting of files containg JSX syntax. Accepts glob patterns. Respects your local .jshintrc file and .gitignore to filter your glob patterns.
|
||||
>
|
||||
> ```
|
||||
npm install -g jsxhint
|
||||
```
|
||||
>
|
||||
> [Check it out on GitHub...](https://github.com/CondeNast/JSXHint)
|
||||
|
||||
|
||||
## Turbo React
|
||||
|
||||
[Ross Allen](https://twitter.com/ssorallen) working at [Mesosphere](http://mesosphere.io/) combined [Turbolinks](https://github.com/rails/turbolinks/), a library used by Ruby on Rails to speed up page transition, and React.
|
||||
|
||||
> "Re-request this page" is just a link to the current page. When you click it, Turbolinks intercepts the GET request and fetchs the full page via XHR.
|
||||
>
|
||||
> The panel is rendered with a random panel- class on each request, and the progress bar gets a random widthX class.
|
||||
>
|
||||
> With Turbolinks alone, the entire <body> would be replaced, and transitions would not happen. In this little demo though, React adds and removes classes and text, and the attribute changes are animated with CSS transitions. The DOM is otherwise left intact.
|
||||
><figure>[](https://turbo-react.herokuapp.com/)</figure>
|
||||
>
|
||||
> [Check out the demo...](https://turbo-react.herokuapp.com/)
|
||||
|
||||
|
||||
## Reactive Table
|
||||
|
||||
[Stoyan Stefanov](http://www.phpied.com/) continues his series of blog posts about React. This one is an introduction tutorial on rendering a simple table with React.
|
||||
|
||||
> React is all about components. So let's build one.
|
||||
>
|
||||
> Let's call it Table (to avoid any confusion what the component is about).
|
||||
>
|
||||
> ```javascript
|
||||
var Table = React.createClass({
|
||||
/*stuff goeth here*/
|
||||
});
|
||||
```
|
||||
>
|
||||
> You see that React components are defined using a regular JS object. Some properties and methods of the object such as render() have special meanings, the rest is upforgrabs.
|
||||
>
|
||||
> [Read the full article...](http://www.phpied.com/reactive-table/)
|
||||
|
||||
143
docs/_posts/2013-11-05-thinking-in-react.md
Normal file
@@ -0,0 +1,143 @@
|
||||
---
|
||||
title: "Thinking in React"
|
||||
layout: post
|
||||
author: Pete Hunt
|
||||
---
|
||||
|
||||
React is, in my opinion, the premier way to build big, fast Web apps with JavaScript. It's scaled very well for us at Facebook and Instagram.
|
||||
|
||||
One of the many great parts of React is how it makes you think about apps as you build them. In this post I'll walk you through the thought process of building a searchable product data table using React.
|
||||
|
||||
## Start with a mock
|
||||
|
||||
Imagine that we already have a JSON API and a mock from our designer. Our designer apparently isn't very good because the mock looks like this:
|
||||
|
||||

|
||||
|
||||
Our JSON API returns some data that looks like this:
|
||||
|
||||
```
|
||||
[
|
||||
{category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football"},
|
||||
{category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball"},
|
||||
{category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball"},
|
||||
{category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch"},
|
||||
{category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5"},
|
||||
{category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7"}
|
||||
];
|
||||
```
|
||||
|
||||
## Step 1: break the UI into a component hierarchy
|
||||
|
||||
The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components!
|
||||
|
||||
But how do you know what should be its own component? Just use the same techniques for deciding if you should create a new function or object. One such technique is the [single responsibility principle](http://en.wikipedia.org/wiki/Single_responsibility_principle), that is, a component should ideally only do one thing. If it ends up growing it should be decomposed into smaller subcomponents.
|
||||
|
||||
Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly your UI (and therefore your component structure) will map nicely onto it. That's because user interfaces and data models tend to adhere to the same *information architecture* which means the work of separating your UI into components is often trivial. Just break it up into components that represent exactly one piece of your data model.
|
||||
|
||||

|
||||
|
||||
You'll see here that we have five components in our simple app. I've italicized the data each component represents.
|
||||
|
||||
1. **`FilterableProductTable` (orange):** contains the entirety of the example
|
||||
2. **`SearchBar` (blue):** receives all *user input*
|
||||
3. **`ProductTable` (green):** displays and filters the *data collection* based on *user input*
|
||||
4. **`ProductCategoryRow` (turquoise):** displays a heading for each *category*
|
||||
5. **`ProductRow` (red):** displays a row for each *product*
|
||||
|
||||
If you look at `ProductTable` you'll see that the table header (containing the "Name" and "Price" labels) isn't its own component. This is a matter of preference and there's an argument to be made either way. For this example I left it as part of `ProductTable` because it is part of rendering the *data collection* which is `ProductTable`'s responsibility. However if this header grows to be complex (i.e. if we were to add affordances for sorting) it would certainly make sense to make this its own `ProductTableHeader` component.
|
||||
|
||||
Now that we've identified the components in our mock, let's arrange them into a hierarchy. This is easy. Components that appear within another component in the mock should appear as a child in the hierarchy:
|
||||
|
||||
* `FilterableProductTable`
|
||||
* `SearchBar`
|
||||
* `ProductTable`
|
||||
* `ProductCategoryRow`
|
||||
* `ProductRow`
|
||||
|
||||
## Step 2: Build a static version in React
|
||||
|
||||
<iframe width="100%" height="300" src="http://jsfiddle.net/6wQMG/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
|
||||
|
||||
Now that you have your component hierarchy it's time to start implementing your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity. It's easiest to decouple these processes because building building a static version requires a lot of typing and no thinking, and adding interactivity requires a lot of thinking and not a lot of typing. We'll see why.
|
||||
|
||||
To build a static version of your app that renders your data model you'll want to build components that reuse other components and pass data using *props*. *props* are a way of passing data from parent to child. If you're familiar with the concept of *state*, **don't use state at all** to build this static version. State is reserved only for interactivity, that is, data that changes over time. Since this is a static version of the app you don't need it.
|
||||
|
||||
You can build top-down or bottom-up. That is, you can either start with building the components higher up in the hierarchy (i.e. starting with `FilterableProductTable`) or with the ones lower in it (`ProductRow`). In simpler examples it's usually easier to go top-down and on larger projects it's easier to go bottom-up and write tests as you build.
|
||||
|
||||
At the end of this step you'll have a library of reusable components that render your data model. The components will only have `render()` methods since this is a static version of your app. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. If you make a change to your underlying data model and call `renderComponent()` again the UI will be updated. It's easy to see how your UI is updated and where to make changes since there's nothing complicated going on since React's **one-way data flow** (also called *one-way binding*) keeps everything modular, easy to reason about, and fast.
|
||||
|
||||
Simply refer to the [React docs](http://facebook.github.io/react/docs/) if you need help executing this step.
|
||||
|
||||
### A brief interlude: props vs state
|
||||
|
||||
There are two types of "model" data in React: props and state. It's important to understand the distinction between the two; skim [the official React docs](http://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html) if you aren't sure what the difference is.
|
||||
|
||||
## Step 3: Identify the minimal (but complete) representation of UI state
|
||||
|
||||
To make your UI interactive you need to be able to trigger changes to your underlying data model. React makes this easy with **state**.
|
||||
|
||||
To build your app correctly you first need to think of the minimal set of mutable state that your app needs. The key here is DRY: *Don't Repeat Yourself*. Figure out what the absolute minimal representation of the state of your application needs to be and compute everything else you need on-demand. For example, if you're building a TODO list, just keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count simply take the length of the TODO items array.
|
||||
|
||||
Think of all of the pieces of data in our example application. We have:
|
||||
|
||||
* The original list of products
|
||||
* The search text the user has entered
|
||||
* The value of the checkbox
|
||||
* The filtered list of products
|
||||
|
||||
Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data:
|
||||
|
||||
1. Is it passed in from a parent via props? If so, it probably isn't state.
|
||||
2. Does it change over time? If not, it probably isn't state.
|
||||
3. Can you compute it based on any other state or props in your component? If so, it's not state.
|
||||
|
||||
The original list of products is passed in as props, so that's not state. The search text and the checkbox seem to be state since they change over time and can't be computed from anything. And finally, the filtered list of products isn't state because it can be computed by combining the original list of products with the search text and value of the checkbox.
|
||||
|
||||
So finally, our state is:
|
||||
|
||||
* The search text the user has entered
|
||||
* The value of the checkbox
|
||||
|
||||
## Step 4: Identify where your state should live
|
||||
|
||||
<iframe width="100%" height="300" src="http://jsfiddle.net/QvHnx/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
|
||||
|
||||
OK, so we've identified what the minimal set of app state is. Next we need to identify which component mutates, or *owns*, this state.
|
||||
|
||||
Remember: React is all about one-way data flow down the component hierarchy. It may not be immediately clear which component should own what state. **This is often the most challenging part for newcomers to understand,** so follow these steps to figure it out:
|
||||
|
||||
For each piece of state in your application:
|
||||
|
||||
* Identify every component that renders something based on that state.
|
||||
* Find a common owner component (a single component above all the components that need the state in the hierarchy).
|
||||
* Either the common owner or another component higher up in the hierarchy should own the state.
|
||||
* If you can't find a component where it makes sense to own the state, create a new component simply for holding the state and add it somewhere in the hierarchy above the common owner component.
|
||||
|
||||
Let's run through this strategy for our application:
|
||||
|
||||
* `ProductTable` needs to filter the product list based on state and `SearchBar` needs to display the search text and checked state.
|
||||
* The common owner component is `FilterableProductTable`.
|
||||
* It conceptually makes sense for the filter text and checked value to live in `FilterableProductTable`
|
||||
|
||||
Cool, so we've decided that our state lives in `FilterableProductTable`. First, add a `getInitialState()` method to `FilterableProductTable` that returns `{filterText: '', inStockOnly: false}` to reflect the initial state of your application. Then pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as a prop. Finally, use these props to filter the rows in `ProductTable` and set the values of the form fields in `SearchBar`.
|
||||
|
||||
You can start seeing how your application will behave: set `filterText` to `"ball"` and refresh your app. You'll see the data table is updated correctly.
|
||||
|
||||
## Step 5: Add inverse data flow
|
||||
|
||||
<iframe width="100%" height="300" src="http://jsfiddle.net/3Vs3Q/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
|
||||
|
||||
So far we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in `FilterableProductTable`.
|
||||
|
||||
React makes this data flow explicit to make it easy to understand how your program works, but it does require a little more typing than traditional two-way data binding. React provides an add-on called `ReactLink` to make this pattern as convenient as two-way binding, but for the purpose of this post we'll keep everything explicit.
|
||||
|
||||
If you try to type or check the box in the current version of the example you'll see that React ignores your input. This is intentional, as we've set the `value` prop of the `input` to always be equal to the `state` passed in from `FilterableProductTable`.
|
||||
|
||||
Let's think about what we want to happen. We want to make sure that whenever the user changes the form we update the state to reflect the user input. Since components should only update their own state, `FilterableProductTable` will pass a callback to `SearchBar` that will fire whenever the state should be updated. We can use the `onChange` event on the inputs to be notified of it. And the callback passed by `FilterableProductTable` will call `setState()` and the app will be updated.
|
||||
|
||||
Though this sounds like a lot it's really just a few lines of code. And it's really explicit how your data is flowing throughout the app.
|
||||
|
||||
## And that's it
|
||||
|
||||
Hopefully this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's extremely easy to read this modular, explicit code. As you start to build large libraries of components you'll appreciate this explicitness and modularity, and with code reuse your lines of code will start to shrink :)
|
||||
125
docs/_posts/2013-11-06-community-roundup-10.md
Normal file
@@ -0,0 +1,125 @@
|
||||
---
|
||||
title: "Community Round-up #10"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
This is the 10th round-up already and React has come quite far since it was open sourced. Almost all new web projects at Khan Academy, Facebook, and Instagram are being developed using React. React has been deployed in a variety of contexts: a Chrome extension, a Windows 8 application, mobile websites, and desktop websites supporting Internet Explorer 8! Language-wise, React is not only being used within JavaScript but also CoffeeScript and ClojureScript.
|
||||
|
||||
The best part is that no drastic changes have been required to support all those use cases. Most of the efforts were targeted at polishing edge cases, performance improvements, and documentation.
|
||||
|
||||
## Khan Academy - Officially moving to React
|
||||
|
||||
[Joel Burget](http://joelburget.com/) announced at Hack Reactor that new front-end code at Khan Academy should be written in React!
|
||||
|
||||
> How did we get the rest of the team to adopt React? Using interns as an attack vector! Most full-time devs had already been working on their existing projects for a while and weren't looking to try something new at the time, but our class of summer interns was just arriving. For whatever reason, a lot of them decided to try React for their projects. Then mentors became exposed through code reviews or otherwise touching the new code. In this way React knowledge diffused to almost the whole team over the summer.
|
||||
>
|
||||
> Since the first React checkin on June 5, we've somehow managed to accumulate 23500 lines of jsx (React-flavored js) code. Which is terrifying in a way - that's a lot of code - but also really exciting that it was picked up so quickly.
|
||||
>
|
||||
> We held three meetings about how we should proceed with React. At the first two we decided to continue experimenting with React and deferred a final decision on whether to adopt it. At the third we adopted the policy that new code should be written in React.
|
||||
>
|
||||
> I'm excited that we were able to start nudging code quality forward. However, we still have a lot of work to do! One of the selling points of this transition is adopting a uniform frontend style. We're trying to upgrade all the code from (really old) pure jQuery and (regular old) Backbone views / Handlebars to shiny React. At the moment all we've done is introduce more fragmentation. We won't be gratuitously updating working code (if it ain't broke, don't fix it), but are seeking out parts of the codebase where we can shoot two birds with one stone by rewriting in React while fixing bugs or adding functionality.
|
||||
>
|
||||
> [Read the full article](http://joelburget.com/backbone-to-react/)
|
||||
|
||||
|
||||
## React: Rethinking best practices
|
||||
|
||||
[Pete Hunt](http://www.petehunt.net/)'s talk at JSConf EU 2013 is now available in video.
|
||||
|
||||
<figure><iframe width="600" height="370" src="//www.youtube.com/embed/x7cQ3mrcKaY" frameborder="0" allowfullscreen></iframe></figure>
|
||||
|
||||
|
||||
## Server-side React with PHP
|
||||
|
||||
[Stoyan Stefanov](http://www.phpied.com/)'s series of articles on React has two new entries on how to execute React on the server to generate the initial page load.
|
||||
|
||||
> This post is an initial hack to have React components render server-side in PHP.
|
||||
>
|
||||
> - Problem: Build web UIs
|
||||
> - Solution: React
|
||||
> - Problem: UI built in JS is anti-SEO (assuming search engines are still noscript) and bad for perceived performance (blank page till JS arrives)
|
||||
> - Solution: [React page](https://github.com/facebook/react-page) to render the first view
|
||||
> - Problem: Can't host node.js apps / I have tons of PHP code
|
||||
> - Solution: Use PHP then!
|
||||
>
|
||||
> [**Read part 1 ...**](http://www.phpied.com/server-side-react-with-php/)
|
||||
>
|
||||
> [**Read part 2 ...**](http://www.phpied.com/server-side-react-with-php-part-2/)
|
||||
>
|
||||
> Rendered markup on the server:
|
||||
> <figure>[](http://www.phpied.com/server-side-react-with-php-part-2/)</figure>
|
||||
|
||||
|
||||
## TodoMVC Benchmarks
|
||||
|
||||
Webkit has a [TodoMVC Benchmark](https://github.com/WebKit/webkit/tree/master/PerformanceTests/DoYouEvenBench) that compares different frameworks. They recently included React and here are the results (average of 10 runs in Chrome 30):
|
||||
|
||||
- **AngularJS:** 4043ms
|
||||
- **AngularJSPerf:** 3227ms
|
||||
- **BackboneJS:** 1874ms
|
||||
- **EmberJS:** 6822ms
|
||||
- **jQuery:** 14628ms
|
||||
- **React:** 2864ms
|
||||
- **VanillaJS:** 5567ms
|
||||
|
||||
[Try it yourself!](http://www.petehunt.net/react/tastejs/benchmark.html)
|
||||
|
||||
Please don't take those numbers too seriously, they only reflect one very specific use case and are testing code that wasn't written with performance in mind.
|
||||
|
||||
Even though React scores as one of the fastest frameworks in the benchmark, the React code is simple and idiomatic. The only performance tweak used is the following function:
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* This is a completely optional performance enhancement that you can implement
|
||||
* on any React component. If you were to delete this method the app would still
|
||||
* work correctly (and still be very performant!), we just use it as an example
|
||||
* of how little code it takes to get an order of magnitude performance improvement.
|
||||
*/
|
||||
shouldComponentUpdate: function (nextProps, nextState) {
|
||||
return (
|
||||
nextProps.todo.id !== this.props.todo.id ||
|
||||
nextProps.todo !== this.props.todo ||
|
||||
nextProps.editing !== this.props.editing ||
|
||||
nextState.editText !== this.state.editText
|
||||
);
|
||||
},
|
||||
```
|
||||
|
||||
By default, React "re-renders" all the components when anything changes. This is usually fast enough that you don't need to care. However, you can provide a function that can tell whether there will be any change based on the previous and next states and props. If it is faster than re-rendering the component, then you get a performance improvement.
|
||||
|
||||
The fact that you can control when components are rendered is a very important characteristic of React as it gives you control over its performance. We are going to talk more about performance in the future, stay tuned.
|
||||
|
||||
## Guess the filter
|
||||
|
||||
[Connor McSheffrey](http://conr.me) implemented a small game using React. The goal is to guess which filter has been used to create the Instagram photo.
|
||||
<figure>[](http://guessthefilter.com/)</figure>
|
||||
|
||||
|
||||
## React vs FruitMachine
|
||||
|
||||
[Andrew Betts](http://trib.tv/), director of the [Financial Times Labs](http://labs.ft.com/), posted an article comparing [FruitMachine](https://github.com/ftlabs/fruitmachine) and React.
|
||||
|
||||
> Eerily similar, no? Maybe Facebook was inspired by Fruit Machine (after all, we got there first), but more likely, it just shows that this is a pretty decent way to solve the problem, and great minds think alike. We're graduating to a third phase in the evolution of web best practice - from intermingling of markup, style and behaviour, through a phase in which those concerns became ever more separated and encapsulated, and finally to a model where we can do that separation at a component level. Developments like Web Components show the direction the web community is moving, and frameworks like React and Fruit Machine are in fact not a lot more than polyfills for that promised behaviour to come.
|
||||
>
|
||||
> [Read the full article...](http://labs.ft.com/2013/10/client-side-layout-engines-react-vs-fruitmachine/)
|
||||
|
||||
Even though we weren't inspired by FruitMachine (React has been used in production since before FruitMachine was open sourced), it's great to see similar technologies emerging and becoming popular.
|
||||
|
||||
## React Brunch
|
||||
|
||||
[Matthew McCray](http://elucidata.net/) implemented [react-brunch](https://npmjs.org/package/react-brunch), a JSX compilation step for [Brunch](http://brunch.io/).
|
||||
|
||||
> Adds React support to brunch by automatically compiling `*.jsx` files.
|
||||
>
|
||||
> You can configure react-brunch to automatically insert a react header (`/** @jsx React.DOM */`) into all `*.jsx` files. Disabled by default.
|
||||
>
|
||||
> Install the plugin via npm with `npm install --save react-brunch`.
|
||||
>
|
||||
> [Read more...](https://npmjs.org/package/react-brunch)
|
||||
|
||||
## Random Tweet
|
||||
|
||||
I'm going to start adding a tweet at the end of each round-up. We'll start with this one:
|
||||
|
||||
<blockquote class="twitter-tweet"><p>This weekend <a href="https://twitter.com/search?q=%23angular&src=hash">#angular</a> died for me. Meet new king <a href="https://twitter.com/search?q=%23reactjs&src=hash">#reactjs</a></p>— Eldar Djafarov ッ (@edjafarov) <a href="https://twitter.com/edjafarov/statuses/397033796710961152">November 3, 2013</a></blockquote>
|
||||
92
docs/_posts/2013-11-18-community-roundup-11.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
title: "Community Round-up #11"
|
||||
layout: post
|
||||
author: Vjeux
|
||||
---
|
||||
|
||||
This round-up is the proof that React has taken off from its Facebook's root: it features three in-depth presentations of React done by external people. This is awesome, keep them coming!
|
||||
|
||||
## Super VanJS 2013 Talk
|
||||
|
||||
[Steve Luscher](https://github.com/steveluscher) working at [LeanPub](https://leanpub.com/) made a 30 min talk at [Super VanJS](https://twitter.com/vanjs). He does a remarkable job at explaining why React is so fast with very exciting demos using the HTML5 Audio API.
|
||||
|
||||
<figure><iframe width="600" height="338" src="//www.youtube.com/embed/1OeXsL5mr4g" frameborder="0" allowfullscreen></iframe></figure>
|
||||
|
||||
|
||||
## React Tips
|
||||
|
||||
[Connor McSheffrey](http://connormcsheffrey.com/) and [Cheng Lou](https://github.com/chenglou) added a new section to the documentation. It's a list of small tips that you will probably find useful while working on React. Since each article is very small and focused, we [encourage you to contribute](http://facebook.github.io/react/tips/introduction.html)!
|
||||
|
||||
- [Inline Styles](http://facebook.github.io/react/tips/inline-styles.html)
|
||||
- [If-Else in JSX](http://facebook.github.io/react/tips/if-else-in-JSX.html)
|
||||
- [Self-Closing Tag](http://facebook.github.io/react/tips/self-closing-tag.html)
|
||||
- [Maximum Number of JSX Root Nodes](http://facebook.github.io/react/tips/maximum-number-of-jsx-root-nodes.html)
|
||||
- [Shorthand for Specifying Pixel Values in style props](http://facebook.github.io/react/tips/style-props-value-px.html)
|
||||
- [Type of the Children props](http://facebook.github.io/react/tips/children-props-type.html)
|
||||
- [Value of null for Controlled Input](http://facebook.github.io/react/tips/controlled-input-null-value.html)
|
||||
- [`componentWillReceiveProps` Not Triggered After Mounting](http://facebook.github.io/react/tips/componentWillReceiveProps-not-triggered-after-mounting.html)
|
||||
- [Props in getInitialState Is an Anti-Pattern](http://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html)
|
||||
- [DOM Event Listeners in a Component](http://facebook.github.io/react/tips/dom-event-listeners.html)
|
||||
- [Load Initial Data via AJAX](http://facebook.github.io/react/tips/initial-ajax.html)
|
||||
- [False in JSX](http://facebook.github.io/react/tips/false-in-jsx.html)
|
||||
|
||||
|
||||
## Intro to the React Framework
|
||||
|
||||
[Pavan Podila](http://blog.pixelingene.com/) wrote an in-depth introduction to React on TutsPlus. This is definitively worth reading.
|
||||
|
||||
> Within a component-tree, data should always flow down. A parent-component should set the props of a child-component to pass any data from the parent to the child. This is termed as the Owner-Owned pair. On the other hand user-events (mouse, keyboard, touches) will always bubble up from the child all the way to the root component, unless handled in between.
|
||||
<figure>[](http://dev.tutsplus.com/tutorials/intro-to-the-react-framework--net-35660)</figure>
|
||||
>
|
||||
> [Read the full article ...](http://dev.tutsplus.com/tutorials/intro-to-the-react-framework--net-35660)
|
||||
|
||||
|
||||
## 140-characters textarea
|
||||
|
||||
[Brian Kim](https://github.com/brainkim) wrote a small textarea component that gradually turns red as you reach the 140-characters limit. Because he only changes the background color, React is smart enough not to mess with the text selection.
|
||||
|
||||
<p data-height="178" data-theme-id="0" data-slug-hash="FECGb" data-user="brainkim" data-default-tab="result" class='codepen'>See the Pen <a href='http://codepen.io/brainkim/pen/FECGb'>FECGb</a> by Brian Kim (<a href='http://codepen.io/brainkim'>@brainkim</a>) on <a href='http://codepen.io'>CodePen</a></p>
|
||||
<script async src="//codepen.io/assets/embed/ei.js"></script>
|
||||
|
||||
|
||||
## Genesis Skeleton
|
||||
|
||||
[Eric Clemmons](http://ericclemmons.github.io/) is working on a "Modern, opinionated, full-stack starter kit for rapid, streamlined application development". The version 0.4.0 has just been released and has first-class support for React.
|
||||
<figure>[](http://genesis-skeleton.com/)</figure>
|
||||
|
||||
|
||||
## AgFlow Talk
|
||||
|
||||
[Robert Zaremba](http://rz.scale-it.pl/) working on [AgFlow](http://www.agflow.com/) recently talked in Poland about React.
|
||||
|
||||
> In a nutshell, I presented why we chose React among other available options (ember.js, angular, backbone ...) in AgFlow, where I’m leading an application development.
|
||||
>
|
||||
> During the talk a wanted to highlight that React is not about implementing a Model, but a way to construct visible components with some state. React is simple. It is super simple, you can learn it in 1h. On the other hand what is model? Which functionality it should provide? React does one thing and does it the best (for me)!
|
||||
>
|
||||
> [Read the full article...](http://rz.scale-it.pl/2013/10/20/frontend_components_in_react.html)
|
||||
|
||||
<figure><iframe src="https://docs.google.com/presentation/d/1JSFbjCuuexwOHCeHWBMNRIJdyfD2Z0ZQwX65WOWkfaI/embed?start=false" frameborder="0" width="600" height="468" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"> </iframe></figure>
|
||||
|
||||
|
||||
## JSX
|
||||
|
||||
[Todd Kennedy](http://tck.io/) working at Condé Nast wrote [JSXHint](https://github.com/CondeNast/JSXHint) and explains in a blog post his perspective on JSX.
|
||||
|
||||
> Lets start with the elephant in the room: JSX?
|
||||
> Is this some sort of template language? Specifically no. This might have been the first big stumbling block. What looks like to be a templating language is actually an in-line DSL that gets transpiled directly into JavaScript by the JSX transpiler.
|
||||
>
|
||||
> Creating elements in memory is quick -- copying those elements into the DOM is where the slowness occurs. This is due to a variety of issues, most namely reflow/paint. Changing the items in the DOM causes the browser to re-paint the display, apply styles, etc. We want to keep those operations to an absolute minimum, especially if we're dealing with something that needs to update the DOM frequently.
|
||||
>
|
||||
> [Read the full article...](http://tck.io/posts/jsxhint_and_react.html)
|
||||
|
||||
|
||||
## Photo Gallery
|
||||
|
||||
[Maykel Loomans](http://miekd.com/), designer at Instagram, wrote a gallery for photos he shot using React.
|
||||
<figure>[](http://photos.miekd.com/xoxo2013/)</figure>
|
||||
|
||||
|
||||
## Random Tweet
|
||||
|
||||
<img src="/react/img/blog/steve_reverse.gif" style="float: right;" />
|
||||
<div style="width: 320px;"><blockquote class="twitter-tweet"><p>I think this reversed gif of Steve Urkel best describes my changing emotions towards the React Lib <a href="http://t.co/JoX0XqSXX3">http://t.co/JoX0XqSXX3</a></p>— Ryan Seddon (@ryanseddon) <a href="https://twitter.com/ryanseddon/statuses/398572848802852864">November 7, 2013</a></blockquote></div>
|
||||
23
docs/_posts/2013-12-18-react-v0.5.2-v0.4.2.md
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
title: "React v0.5.2, v0.4.2"
|
||||
layout: post
|
||||
author: Paul O'Shannessy
|
||||
---
|
||||
|
||||
Today we're releasing an update to address a potential XSS vulnerability that can arise when using user data as a `key`. Typically "safe" data is used for a `key`, for example, an id from your database, or a unique hash. However there are cases where it may be reasonable to use user generated content. A carefully crafted piece of content could result in arbitrary JS execution. While we make a very concerted effort to ensure all text is escaped before inserting it into the DOM, we missed one case. Immediately following the discovery of this vulnerability, we performed an audit to ensure we this was the only such vulnerability.
|
||||
|
||||
This only affects v0.5.x and v0.4.x. Versions in the 0.3.x family are unaffected.
|
||||
|
||||
Updated versions are available for immediate download via npm, bower, and on our [download page][download].
|
||||
|
||||
We take security very seriously at Facebook. For most of our products, users don't need to know that a security issue has been fixed. But with libraries like React, we need to make sure developers using React have access to fixes to keep their users safe.
|
||||
|
||||
While we've encouraged responsible disclosure as part of [Facebook's whitehat bounty program][bounty] since we launched, we don't have a good process for notifying our users. Hopefully we don't need to use it, but moving forward we'll set up a little bit more process to ensure the safety of our users. Ember.js has [an excellent policy][ember] which we may use as our model.
|
||||
|
||||
You can learn more about the vulnerability discussed here: [CVE-2013-7035][cve].
|
||||
|
||||
[download]: http://facebook.github.io/react/downloads.html
|
||||
[bounty]: https://www.facebook.com/whitehat/
|
||||
[ember]: http://emberjs.com/security/
|
||||
[cve]: https://groups.google.com/forum/#!topic/reactjs/OIqxlB2aGfU
|
||||
|
||||
15
docs/blog/all.html
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Blog
|
||||
layout: default
|
||||
sectionid: blog
|
||||
id: all-posts
|
||||
---
|
||||
|
||||
<section class="content wrap documentationContent nosidebar">
|
||||
<div class="inner-content">
|
||||
<h1>All Posts</h1>
|
||||
{% for page in site.posts %}
|
||||
<p><strong><a href="/react{{ page.url }}">{{ page.title }}</a></strong> on {{ page.date | date: "%B %e, %Y" }} by {{ page.author }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
@@ -7,22 +7,28 @@ sectionid: blog
|
||||
<section class="content wrap blogContent">
|
||||
{% include nav_blog.html %}
|
||||
<div class="inner-content">
|
||||
{% for page in site.posts %}
|
||||
{% for page in paginator.posts %}
|
||||
<div class="post-list-item">
|
||||
<h1><a href="/react{{ page.url }}">{{ page.title }}</a></h1>
|
||||
<p class="meta">{{ page.date | date: "%B %e, %Y" }} by {{ page.author }}</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<hr />
|
||||
<div class="post">
|
||||
{{ page.excerpt }}
|
||||
{% if page.excerpt != page.content %}
|
||||
<p>
|
||||
<a href="/react{{ page.url }}">Continue Reading →</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{{ page.content }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="pagination">
|
||||
{% if paginator.previous_page %}
|
||||
<a href="/react/{{ paginator.previous_page_path }}" class="previous">
|
||||
« Previous Page
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if paginator.next_page %}
|
||||
<a href="/react{{ paginator.next_page_path }}" class="next">
|
||||
Next Page »
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -82,7 +82,7 @@ var div = React.DOM.div;
|
||||
var app = <div className="appClass">Hello, React!</div>;
|
||||
```
|
||||
|
||||
### React Component Components
|
||||
### React Composite Components
|
||||
|
||||
To construct an instance of a composite component, create a variable that
|
||||
references the class.
|
||||
@@ -92,7 +92,7 @@ var MyComponent = React.createClass({/*...*/});
|
||||
var app = <MyComponent someProperty={true} />;
|
||||
```
|
||||
|
||||
See [Component Basics](component-basics.html) to learn more about components.
|
||||
See [Multiple Components](multiple-components.html) to learn more about using composite components.
|
||||
|
||||
> Note:
|
||||
>
|
||||
@@ -157,14 +157,6 @@ It's easy to add comments within your JSX; they're just JS expressions:
|
||||
var content = <Container>{/* this is a comment */}<Nav /></Container>;
|
||||
```
|
||||
|
||||
## Tooling
|
||||
|
||||
Beyond the compilation step, JSX does not require any special tools.
|
||||
|
||||
* Many editors already include reasonable support for JSX (Vim, Emacs js2-mode).
|
||||
* Linting provides accurate line numbers after compiling without sourcemaps.
|
||||
* Elements use standard scoping so linters can find usage of out-of-scope
|
||||
components.
|
||||
|
||||
## Prior Work
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ next: interactivity-and-dynamic-uis.html
|
||||
|
||||
JSX looks like HTML but there are some important differences you may run into.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> For DOM differences, such as the inline `style` attribute, check [here](dom-differences.html).
|
||||
|
||||
## Whitespace Removal
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ With React you simply pass your event handler as a camelCased prop similar to ho
|
||||
If you'd like to use React on a touch device (i.e. a phone or tablet), simply call `React.initializeTouchEvents(true);` to turn them on.
|
||||
|
||||
|
||||
## Under the Hood: autoBind and Event Delegation
|
||||
## Under the Hood: Autobinding and Event Delegation
|
||||
|
||||
Under the hood React does a few things to keep your code performant and easy to understand.
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ React.renderComponent(
|
||||
|
||||
In the above example, instances of `Avatar` *own* instances of `ProfilePic` and `ProfileLink`. In React, **an owner is the component that sets the `props` of other components**. More formally, if a component `X` is created in component `Y`'s `render()` method, it is said that `X` is *owned by* `Y`. As discussed earlier, a component cannot mutate its `props` — they are always consistent with what its owner sets them to. This key property leads to UIs that are guaranteed to be consistent.
|
||||
|
||||
It's important to draw a distinciton between the owner-ownee relationship and the parent-child relationship. The owner-ownee relationship is specific to React, while the parent-child relationship is simply the one you know and love from the DOM. In the example above, `Avatar` owns the `div`, `ProfilePic` and `ProfileLink` instances, and `div` is the **parent** (but not owner) of the `ProfilePic` and `ProfileLink` instances.
|
||||
It's important to draw a distinction between the owner-ownee relationship and the parent-child relationship. The owner-ownee relationship is specific to React, while the parent-child relationship is simply the one you know and love from the DOM. In the example above, `Avatar` owns the `div`, `ProfilePic` and `ProfileLink` instances, and `div` is the **parent** (but not owner) of the `ProfilePic` and `ProfileLink` instances.
|
||||
|
||||
|
||||
## Children
|
||||
@@ -144,7 +144,7 @@ In React, data flows from owner to owned component through `props` as discussed
|
||||
|
||||
You may be thinking that it's expensive to react to changing data if there are a large number of nodes under an owner. The good news is that JavaScript is fast and `render()` methods tend to be quite simple, so in most applications this is extremely fast. Additionally, the bottleneck is almost always the DOM mutation and not JS execution and React will optimize this for you using batching and change detection.
|
||||
|
||||
However, sometimes you really want to have fine-grained control over your performance. In that case, simply override `shouldComponentUpdate()` to return false when you want React to skip processing of a subtree. See [the React reference docs](./reference.html) for more information.
|
||||
However, sometimes you really want to have fine-grained control over your performance. In that case, simply override `shouldComponentUpdate()` to return false when you want React to skip processing of a subtree. See [the React reference docs](component-specs.html) for more information.
|
||||
|
||||
> Note:
|
||||
>
|
||||
|
||||
@@ -35,7 +35,7 @@ React.createClass({
|
||||
someClass: React.PropTypes.instanceOf(SomeClass),
|
||||
|
||||
// You can chain any of the above with isRequired to make sure an error is
|
||||
// thrown if the prop isn't provide.
|
||||
// thrown if the prop isn't provided.
|
||||
requiredFunc: React.PropTypes.func.isRequired
|
||||
|
||||
// You can also specify a custom validator.
|
||||
@@ -77,7 +77,7 @@ A common type of React component is one that extends a basic HTML in a simple wa
|
||||
|
||||
var CheckLink = React.createClass({
|
||||
render: function() {
|
||||
// transferPropsTo() will take any props pased to CheckLink
|
||||
// transferPropsTo() will take any props passed to CheckLink
|
||||
// and copy them to <a>
|
||||
return this.transferPropsTo(<a>{'√ '}{this.props.children}</a>);
|
||||
}
|
||||
|
||||
@@ -130,3 +130,18 @@ For HTML, this easily allows developers to supply multiline values. However, sin
|
||||
```
|
||||
|
||||
If you *do* decide to use children, they will behave like `defaultValue`.
|
||||
|
||||
|
||||
### Why Select Value?
|
||||
|
||||
The selected `<option>` in an HTML `<select>` is normally specified through that option's `selected` attribute. In React, in order to make components easier to manipulate, the following format is adopted instead:
|
||||
|
||||
```javascript
|
||||
<select value="B">
|
||||
<option value="A">Apple</option>
|
||||
<option value="B">Banana</option>
|
||||
<option value="C">Cranberry</option>
|
||||
</select>
|
||||
```
|
||||
|
||||
To make an uncontrolled component, `defaultValue` is used instead.
|
||||
|
||||
@@ -110,23 +110,25 @@ _Mounted_ composite components also support the following methods:
|
||||
> calling `this.getDOMNode()`.
|
||||
|
||||
|
||||
## Browser Suppport and Polyfills
|
||||
## Browser Support and Polyfills
|
||||
|
||||
At Facebook, we support older browsers, including IE8. We've had polyfills in place for a long time to allow us to write forward-thinking JS. This means we don't have a bunch of hacks scattered throughout our codebase and we can still expect our code to "just work". For example, instead of seeing `+new Date()`, we can just write `Date.now()`. Since the open source React is the same as what we use internally, we've carried over this philosophy of using forward thinking JS.
|
||||
|
||||
In addition to that philosphy, we've also taken the stance that we, as authors of a JS library, should not be shipping polyfills as a part of our library. If every library did this, there's a good chance you'd be sending down the same polyfill multiple times, which could be a sizable chunk of dead code. If your product needs to support older browsers, chances are you're already using something like [es5-shim](https://github.com/kriskowal/es5-shim).
|
||||
In addition to that philosophy, we've also taken the stance that we, as authors of a JS library, should not be shipping polyfills as a part of our library. If every library did this, there's a good chance you'd be sending down the same polyfill multiple times, which could be a sizable chunk of dead code. If your product needs to support older browsers, chances are you're already using something like [es5-shim](https://github.com/kriskowal/es5-shim).
|
||||
|
||||
|
||||
### Polyfills Needed to Support Older Browsers
|
||||
|
||||
These six functions can be polyfilled using `es5-shim.js` from [kriskowal's es5-shim](https://github.com/kriskowal/es5-shim):
|
||||
|
||||
* `Array.isArray`
|
||||
* `Array.prototype.forEach`
|
||||
* `Array.prototype.indexOf`
|
||||
* `Function.prototype.bind`
|
||||
* `Array.prototype.some`
|
||||
* `Date.now`
|
||||
* `Array.prototype.some` (also in `es5-shim.js`)
|
||||
* `Function.prototype.bind`
|
||||
|
||||
All of these can be polyfilled using `es5-shim.js` from [https://github.com/kriskowal/es5-shim](https://github.com/kriskowal/es5-shim).
|
||||
Other required polyfills:
|
||||
|
||||
* `console.*` - Only needed when not using the minified build. If you need to polyfill this, try [https://github.com/paulmillr/console-polyfill](https://github.com/paulmillr/console-polyfill).
|
||||
* `Object.create` - Provided in `es5-sham.js` @ [https://github.com/kriskowal/es5-shim](https://github.com/kriskowal/es5-shim).
|
||||
* `Object.create` – Provided by `es5-sham.js` from [kriskowal's es5-shim](https://github.com/kriskowal/es5-shim).
|
||||
* `console.*` – Only needed when using the unminified build. If you need to polyfill this, try [paulmillr's console-polyfill](https://github.com/paulmillr/console-polyfill).
|
||||
|
||||
@@ -39,7 +39,7 @@ Consider the case when you wish to tell an `<input />` element (that exists with
|
||||
```
|
||||
|
||||
|
||||
Notice how, in this example, we want to "tell" the input something - something that it cannot infer from it's props over time. In this case we want to "tell" it that it should now become focused. However, there are some challenges. What is returned from `render()`` is not your actual composition of "child" components, it is merely a *description* of the children at a particular instance in time - a snapshot, if you will.
|
||||
Notice how, in this example, we want to "tell" the input something - something that it cannot infer from its props over time. In this case we want to "tell" it that it should now become focused. However, there are some challenges. What is returned from `render()` is not your actual composition of "child" components, it is merely a *description* of the children at a particular instance in time - a snapshot, if you will.
|
||||
|
||||
> Note:
|
||||
>
|
||||
@@ -115,7 +115,7 @@ It's as simple as:
|
||||
});
|
||||
```
|
||||
|
||||
In this example, our render function returns a description of an `<input />` instance. But the true instance is accessed via `this.refs.theInput`. As long as a child component with `ref="theInput"` is returned from render, `this.refs.theInput` will access the the proper instance. This even works on higher level (non-DOM) components such as `<Typeahead ref="myTypeahead" />`.
|
||||
In this example, our render function returns a description of an `<input />` instance. But the true instance is accessed via `this.refs.theInput`. As long as a child component with `ref="theInput"` is returned from render, `this.refs.theInput` will access the proper instance. This even works on higher level (non-DOM) components such as `<Typeahead ref="myTypeahead" />`.
|
||||
|
||||
|
||||
## Summary
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
---
|
||||
id: tooling-integration
|
||||
title: Tooling integration
|
||||
title: Tooling Integration
|
||||
layout: docs
|
||||
permalink: tooling-integration.html
|
||||
prev: more-about-refs.html
|
||||
next: reference.html
|
||||
next: addons.html
|
||||
---
|
||||
|
||||
Every project uses a different system for building and deploying JavaScript. We've tried to make React as environment-agnostic as possible.
|
||||
|
||||
## React
|
||||
|
||||
## CDN-hosted React
|
||||
### CDN-hosted React
|
||||
|
||||
We provide CDN-hosted versions of React [on our download page](/react/downloads.html). These prebuilt files use the UMD module format. Dropping them in with a simple `<script>` tag will inject a `React` global into your environment. It should also work out-of-the-box in CommonJS and AMD environments.
|
||||
|
||||
|
||||
## Using master
|
||||
### Using master
|
||||
|
||||
We have instructions for building from `master` [in our GitHub repository](https://github.com/facebook/react). We build a tree of CommonJS modules under `build/modules` which you can drop into any environment or packaging tool that supports CommonJS.
|
||||
|
||||
## JSX
|
||||
|
||||
## In-browser JSX Transform
|
||||
### In-browser JSX Transform
|
||||
|
||||
If you like using JSX, we provide an in-browser JSX transformer for development [on our download page](/react/downloads.html). Simply include a `<script type="text/jsx">` tag to engage the JSX transformer. Be sure to include the `/** @jsx React.DOM */` comment as well, otherwise the transformer will not run the transforms.
|
||||
|
||||
@@ -29,16 +31,30 @@ If you like using JSX, we provide an in-browser JSX transformer for development
|
||||
> The in-browser JSX transformer is fairly large and results in extraneous computation client-side that can be avoided. Do not use it in production — see the next section.
|
||||
|
||||
|
||||
## Productionizing: Precompiled JSX
|
||||
### Productionizing: Precompiled JSX
|
||||
|
||||
If you have [npm](http://npmjs.org/), you can simply run `npm install -g react-tools` to install our command-line `jsx` tool. This tool will translate files that use JSX syntax to plain JavaScript files that can run directly in the browser. It will also watch directories for you and automatically transform files when they are changed; for example: `jsx --watch src/ build/`. Run `jsx --help` for more information on how to use this tool.
|
||||
|
||||
|
||||
## Helpful Open-Source Projects
|
||||
### Helpful Open-Source Projects
|
||||
|
||||
The open-source community has built tools that integrate JSX with several build systems.
|
||||
|
||||
* [reactify](https://github.com/andreypopp/reactify) - use JSX with [browserify](http://browserify.org/).
|
||||
* [reactify](https://github.com/andreypopp/reactify) - use JSX with [browserify](http://browserify.org/)
|
||||
* [grunt-react](https://github.com/ericclemmons/grunt-react) - [grunt](http://gruntjs.com/) task for JSX
|
||||
* [require-jsx](https://github.com/seiffert/require-jsx) - use JSX with [require.js](http://requirejs.org/)
|
||||
* [reactapp](https://github.com/jordwalke/reactapp) - a sample project to get up-and-running with React quickly
|
||||
* [pyReact](https://github.com/facebook/react-python) - use JSX with [Python](http://www.python.org/)
|
||||
* [react-rails](https://github.com/facebook/react-rails) - use JSX with [Ruby on Rails](http://rubyonrails.org/)
|
||||
|
||||
|
||||
### Syntax Highlighting & Linting
|
||||
|
||||
* Many editors already include reasonable support for JSX (Vim, Emacs js2-mode).
|
||||
* [JSX syntax highlighting](https://github.com/yungsters/sublime/blob/master/tmLanguage/JavaScript%20(JSX\).tmLanguage) is available for Sublime Text and other editors
|
||||
that support `*.tmLanguage`.
|
||||
* Linting provides accurate line numbers after compiling without sourcemaps.
|
||||
* Elements use standard scoping so linters can find usage of out-of-scope components.
|
||||
|
||||
## React Page
|
||||
|
||||
To get started on a new project, you can use [react-page](https://github.com/facebook/react-page/), a complete React project creator. It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.
|
||||
|
||||
16
docs/docs/09-addons.md
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
id: addons
|
||||
title: Add-ons
|
||||
layout: docs
|
||||
permalink: addons.html
|
||||
prev: tooling-integration.html
|
||||
next: animation.html
|
||||
---
|
||||
|
||||
`React.addons` is where we park some useful utilities for building React apps. **These should be considered experimental** but will eventually be rolled into core or a blessed utilities library:
|
||||
|
||||
- `ReactTransitions`, for dealing with animations and transitions that are usually not simple to implement, such as before a component's removal.
|
||||
- `ReactLink`, to simplify the coordination between user's form input data and and the component's state.
|
||||
- `classSet`, for manipulating the DOM `class` string a bit more cleanly.
|
||||
|
||||
To get the add-ons, use `react-with-addons.js` (and its minified counterpart) rather than the common `react.js`.
|
||||
@@ -1,209 +0,0 @@
|
||||
---
|
||||
id: reference
|
||||
title: Reference
|
||||
layout: docs
|
||||
permalink: reference.html
|
||||
prev: tooling-integration.html
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
### Production Apps
|
||||
|
||||
* All of [Instagram.com](http://instagram.com/) is built on React.
|
||||
* Many components on [Facebook.com](http://www.facebook.com/), including the commenting interface, ads creation flows, and page insights.
|
||||
* [Khan Academy](http://khanacademy.org/) is using React for its question editor.
|
||||
|
||||
|
||||
### Sample Code
|
||||
|
||||
* We've included [a step-by-step comment box tutorial](./tutorial.html).
|
||||
* [The React starter kit](/react/downloads.html) includes several examples which you can [view online in our GitHub repository](https://github.com/facebook/react/tree/master/examples/).
|
||||
* [reactapp](https://github.com/jordwalke/reactapp) is a simple app template to get you up-and-running quickly with React.
|
||||
* [React one-hour email](https://github.com/petehunt/react-one-hour-email/commits/master) goes step-by-step from a static HTML mock to an interactive email reader (written in just one hour!)
|
||||
* [Rendr + React app template](https://github.com/petehunt/rendr-react-template/) demonstrates how to use React's server rendering capabilities.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### React
|
||||
|
||||
`React` is the entry point to the React framework. If you're using one of the prebuilt packages it's available as a global; if you're using CommonJS modules you can `require()` it.
|
||||
|
||||
|
||||
#### React.DOM
|
||||
|
||||
`React.DOM` provides all of the standard HTML tags needed to build a React app. You generally don't use it directly; instead, just include it as part of the `/** @jsx React.DOM */` docblock.
|
||||
|
||||
|
||||
#### React.initializeTouchEvents
|
||||
|
||||
```javascript
|
||||
initializeTouchEvents(boolean shouldUseTouch)
|
||||
```
|
||||
|
||||
Configure React's event system to handle touch events on mobile devices.
|
||||
|
||||
|
||||
#### React.createClass
|
||||
|
||||
```javascript
|
||||
function createClass(object specification)
|
||||
```
|
||||
|
||||
Creates a component given a specification. A component implements a `render` method which returns **one single** child. That child may have an arbitrarily deep child structure. One thing that makes components different than a standard prototypal classes is that you don't need to call new on them. They are convenience wrappers that construct backing instances (via new) for you.
|
||||
|
||||
|
||||
#### React.renderComponent
|
||||
|
||||
```javascript
|
||||
ReactComponent renderComponent(ReactComponent container, DOMElement container)
|
||||
```
|
||||
|
||||
Renders a React component into the DOM in the supplied `container`.
|
||||
|
||||
If the React component was previously rendered into `container`, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React component.
|
||||
|
||||
|
||||
#### React.unmountAndReleaseReactRootNode
|
||||
|
||||
```javascript
|
||||
unmountAndReleaseReactRootNode(DOMElement container)
|
||||
```
|
||||
|
||||
Remove a mounted React component from the DOM and clean up its event handlers and state.
|
||||
|
||||
|
||||
#### React.renderComponentToString
|
||||
|
||||
```javascript
|
||||
renderComponentToString(ReactComponent component, function callback)
|
||||
```
|
||||
|
||||
Render a component to its initial HTML. This should only be used on the server. React will call `callback` with an HTML string when the markup is ready. You can use this method to create static site generators, or you can generate HTML on the server and send it down to have a very fast initial page load. If you call `React.renderComponent()` on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
|
||||
|
||||
|
||||
### AbstractEvent
|
||||
|
||||
Your event handlers will be passed instances of `AbstractEvent`, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event (such as `stopPropagation()` and `preventDefault()`) except they work exactly the same across all browsers.
|
||||
|
||||
If you find that you need the underlying browser event for some reason, simply use the `nativeEvent` attribute to get it.
|
||||
|
||||
|
||||
### ReactComponent
|
||||
|
||||
Component classses created by `createClass()` return instances of `ReactComponent` when called. Most of the time when you're using React you're either creating or consuming `ReactComponent`s.
|
||||
|
||||
|
||||
#### getDOMNode
|
||||
|
||||
```javascript
|
||||
DOMElement getDOMNode()
|
||||
```
|
||||
|
||||
If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements.
|
||||
|
||||
|
||||
#### setProps
|
||||
|
||||
```javascript
|
||||
setProps(object nextProps)
|
||||
```
|
||||
|
||||
When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with `renderComponent()`. Simply call `setProps()` to change its properties and trigger a re-render.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> This method can only be called on a root-level component. That is, it's only available on the component passed directly to `renderComponent()` and none of its children. If you're inclined to use `setProps()` on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in `render()`.
|
||||
|
||||
|
||||
#### replaceProps
|
||||
|
||||
```javascript
|
||||
replaceProps(object nextProps)
|
||||
```
|
||||
|
||||
Like `setProps()` but deletes any pre-existing props that are not in nextProps.
|
||||
|
||||
|
||||
#### transferPropsTo
|
||||
|
||||
```javascript
|
||||
ReactComponent transferPropsTo(ReactComponent targetComponent)
|
||||
```
|
||||
|
||||
Transfer properties from this component to a target component that have not already been set on the target component. This is usually used to pass down properties to the returned root component. `targetComponent`, now updated with some new props is returned as a convenience.
|
||||
|
||||
|
||||
#### setState
|
||||
|
||||
```javascript
|
||||
setState(object nextState[, function callback])
|
||||
```
|
||||
|
||||
Merges nextState with the current state. This is the primary method you use to trigger UI updates from event handlers and server request callbacks. In addition, you can supply an optional callback function that is executed once `setState` is completed.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> *NEVER* mutate `this.state` directly. As calling `setState()` afterwards may replace the mutation you made. Treat `this.state` as if it were immutable.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> `setState()` does not immediately mutate `this.state` but creates a pending state transition. Accessing `this.state` after calling this method can potentially return the existing value.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> There is no guarantee of synchronous operation of calls to `setState` and calls may be batched for performance gains.
|
||||
|
||||
|
||||
#### replaceState
|
||||
|
||||
```javascript
|
||||
replaceState(object nextState[, function callback])
|
||||
```
|
||||
|
||||
Like `setState()` but deletes any pre-existing state keys that are not in nextState.
|
||||
|
||||
|
||||
#### forceUpdate()
|
||||
|
||||
```javascript
|
||||
forceUpdate([function callback])
|
||||
```
|
||||
|
||||
If your `render()` method reads from something other than `this.props` or `this.state` you'll need to tell React when it needs to re-run `render()`. Use `forceUpdate()` to cause React to automatically re-render. This will cause `render()` to be called on the component and all of its children but React will only update the DOM if the markup changes.
|
||||
|
||||
Normally you should try to avoid all uses of `forceUpdate()` and only read from `this.props` and `this.state` in `render()`. This makes your application much simpler and more efficient.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> There is no guarantee of synchronous operation of calls to `forceUpdate` and calls may be batched for performance gains.
|
||||
|
||||
|
||||
#### Lifecycle methods
|
||||
|
||||
```javascript
|
||||
object getInitialState()
|
||||
componentWillMount()
|
||||
componentDidMount(DOMElement domNode)
|
||||
componentWillReceiveProps(object nextProps)
|
||||
boolean shouldComponentUpdate(object nextProps, object nextState)
|
||||
componentWillUpdate(object nextProps, object nextState)
|
||||
ReactComponent render()
|
||||
componentDidUpdate(object prevProps, object prevState, DOMElement domNode)
|
||||
componentWillUnmount()
|
||||
```
|
||||
|
||||
See the [working with the browser](./working-with-the-browser.html) documentation for more details on these lifecycle methods.
|
||||
|
||||
|
||||
## DOM Differences
|
||||
|
||||
React has implemented a browser-independent events and DOM system for performance and cross-browser compatibility reasons. We took the opportunity to clean up a few rough edges in browser DOM implementations.
|
||||
|
||||
* All events (including submit) bubble correctly per the W3C spec
|
||||
* All event objects conform to the W3C spec
|
||||
* All DOM properties and attributes (including event handlers) should be camelCased to be consistent with standard JavaScript style. We intentionally break with the spec here, since the spec is inconsistent.
|
||||
* The `style` attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM `style` JavaScript property, is more efficient, and prevents XSS security holes.
|
||||
* `onChange` behaves as you would expect it to: whenever a form field is changed this event is fired rather than inconsistently on blur. We intentionally break from existing browser behavior because `onChange` is a misnomer for its behavior and React relies on this event to react to user input in real time.
|
||||
99
docs/docs/09.1-animation.md
Normal file
@@ -0,0 +1,99 @@
|
||||
---
|
||||
id: animation
|
||||
title: Animation
|
||||
layout: docs
|
||||
permalink: animation.html
|
||||
prev: addons.html
|
||||
next: two-way-binding-helpers.html
|
||||
---
|
||||
|
||||
`ReactTransitions` is an easy way to perform CSS transitions and animations when a React component enters or leaves the DOM. It's inspired by the excellent [ng-animate](http://www.nganimate.org/) library.
|
||||
|
||||
## Getting Started
|
||||
|
||||
`ReactTransitionGroup` is the interface to `ReactTransitions`. This is a simple element that wraps all of the components you are interested in animating. Here's an example where we fade list items in and out.
|
||||
|
||||
```javascript{22-24}
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var ReactTransitionGroup = React.addons.TransitionGroup;
|
||||
|
||||
var TodoList = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {items: ['hello', 'world', 'click', 'me']};
|
||||
},
|
||||
handleAdd: function() {
|
||||
var newItems =
|
||||
this.state.items.concat([prompt('Enter some text')]);
|
||||
this.setState({items: newItems});
|
||||
},
|
||||
handleRemove: function(i) {
|
||||
var newItems = this.state.items;
|
||||
newItems.splice(i, 1)
|
||||
this.setState({items: newItems});
|
||||
},
|
||||
render: function() {
|
||||
var items = this.state.items.map(function(item, i) {
|
||||
return (
|
||||
<div key={i} onClick={this.handleRemove.bind(this, i)}>
|
||||
{item}
|
||||
</div>
|
||||
);
|
||||
}.bind(this));
|
||||
return (
|
||||
<div>
|
||||
<div><button onClick={this.handleAdd} /></div>
|
||||
<ReactTransitionGroup transitionName="example">
|
||||
{items}
|
||||
</ReactTransitionGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
In this component, when a new item is added to `ReactTransitionGroup` it will get the `example-enter` CSS class and the `example-enter-active` CSS class added in the next tick. This is a convention based on the `transitionName` prop.
|
||||
|
||||
You can use these classes to trigger a CSS animation or transition. For example, try adding this CSS and adding a new list item:
|
||||
|
||||
```css
|
||||
.example-enter {
|
||||
opacity: 0.01;
|
||||
transition: opacity .5s ease-in;
|
||||
}
|
||||
|
||||
.example-enter.example-enter-active {
|
||||
opacity: 1;
|
||||
}
|
||||
```
|
||||
|
||||
You'll notice that when you try to remove an item `ReactTransitionGroup` keeps it in the DOM. If you're using an unminified build of React with add-ons you'll see a warning that React was expecting an animation or transition to occur. That's because `ReactTransitionGroup` keeps your DOM elements on the page until the animation completes. Try adding this CSS:
|
||||
|
||||
```css
|
||||
.example-leave {
|
||||
opacity: 1;
|
||||
transition: opacity .5s ease-in;
|
||||
}
|
||||
|
||||
.example-leave.example-leave-active {
|
||||
opacity: 0.01;
|
||||
}
|
||||
```
|
||||
|
||||
## Disabling Animations
|
||||
|
||||
You can disable animating `enter` or `leave` animations if you want. For example, sometimes you may want an `enter` animation and no `leave` animation, but `ReactTransitionGroup` waits for an animation to complete before removing your DOM node. You can add `transitionEnter={false}` or `transitionLeave={false}` props to `ReactTransitionGroup` to disable these animations.
|
||||
|
||||
## Rendering a Different Component
|
||||
|
||||
By default `ReactTransitionGroup` renders as a `span`. You can change this behavior by providing a `component` prop. For example, here's how you would render a `<ul>`:
|
||||
|
||||
```javascript{3}
|
||||
<ReactTransitionGroup
|
||||
transitionName="example"
|
||||
component={React.DOM.ul}>
|
||||
...
|
||||
</ReactTransitionGroup>
|
||||
```
|
||||
|
||||
Every DOM component is under `React.DOM`. However, `component` does not need to be a DOM component. It can be any React component you want; even ones you've written yourself!
|
||||
117
docs/docs/09.2-form-input-binding-sugar.md
Normal file
@@ -0,0 +1,117 @@
|
||||
---
|
||||
id: two-way-binding-helpers
|
||||
title: Two-Way Binding Helpers
|
||||
layout: docs
|
||||
permalink: two-way-binding-helpers.html
|
||||
prev: animation.html
|
||||
next: class-name-manipulation.html
|
||||
---
|
||||
|
||||
`ReactLink` is an easy way to express two-way binding with React.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> If you're new to the framework, note that `ReactLink` is not needed for most applications and should be used cautiously.
|
||||
|
||||
In React, data flows one way: from owner to child. This is because data only flows one direction in [the Von Neumann model of computing](http://en.wikipedia.org/wiki/Von_Neumann_architecture). You can think of it as "one-way data binding."
|
||||
|
||||
However, there are lots of applications that require you to read some data and flow it back into your program. For example, when developing forms, you'll often want to update some React `state` when you receive user input. Or perhaps you want to perform layout in JavaScript and react to changes in some DOM element size.
|
||||
|
||||
In React, you would implement this by listening to a "change" event, read from your data source (usually the DOM) and call `setState()` on one of your components. "Closing the data flow loop" explicitly leads to more understandable and easier-to-maintain programs. See [our forms documentation](./forms.html) for more information.
|
||||
|
||||
Two-way binding -- implicitly enforcing that some value in the DOM is always consistent with some React `state` -- is concise and supports a wide variety of applications. We've provided `ReactLink`: syntactic sugar for setting up the common data flow loop pattern described above, or "linking" some data source to React `state`.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> ReactLink is just a thin wrapper and convention around the `onChange`/`setState()` pattern. It doesn't fundamentally change how data flows in your React application.
|
||||
|
||||
## ReactLink: Before and After
|
||||
|
||||
Here's a simple form example without using `ReactLink`:
|
||||
|
||||
```javascript
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var NoLink = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {value: 'Hello!'};
|
||||
},
|
||||
handleChange: function(event) {
|
||||
this.setState({value: event.target.value});
|
||||
},
|
||||
render: function() {
|
||||
var value = this.state.value;
|
||||
return <input type="text" value={value} onChange={this.handleChange} />;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
This works really well and it's very clear how data is flowing, however with a lot of form fields it could get a bit verbose. Let's use `ReactLink` to save us some typing:
|
||||
|
||||
```javascript{4,9}
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var WithLink = React.createClass({
|
||||
mixins: [React.addons.LinkedStateMixin],
|
||||
getInitialState: function() {
|
||||
return {value: 'Hello!'};
|
||||
},
|
||||
render: function() {
|
||||
return <input type="text" valueLink={this.linkState('value')} />;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
`LinkedStateMixin` adds a method ot your React component called `linkState()`. `linkState()` returns a `ReactLink` object which contains the current value of the React state and a callback to change it.
|
||||
|
||||
`ReactLink` objects can be passed up and down the tree as props, so it's easy (and explicit) to set up two-way binding between a component deep in the hierarchy and state that lives higher in the hierarchy.
|
||||
|
||||
## Under the Hood
|
||||
|
||||
There are two sides to `ReactLink`: the place where you create the `ReactLink` instance and the place where you use it. To prove how simple `ReactLink` is, let's rewrite each side separately to be more explicit.
|
||||
|
||||
### ReactLink Without LinkedStateMixin
|
||||
|
||||
```javascript{7-9,11-14}
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var WithoutMixin = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {value: 'Hello!'};
|
||||
},
|
||||
handleChange: function(newValue) {
|
||||
this.setState({value: newValue});
|
||||
},
|
||||
render: function() {
|
||||
var valueLink = {
|
||||
value: this.state.value,
|
||||
requestChange: this.handleChange
|
||||
};
|
||||
return <input type="text" valueLink={valueLink} />;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
As you can see, `ReactLink` objects are very simple objects that just have a `value` and `requestChange` prop. And `LinkedStateMixin` is similarly simple: it just populates those fields with a value from `this.state` and a callback that calls `this.setState()`.
|
||||
|
||||
### ReactLink Without valueLink
|
||||
|
||||
```javascript
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var WithoutLink = React.createClass({
|
||||
mixins: [React.addons.LinkedStateMixin],
|
||||
getInitialState: function() {
|
||||
return {value: 'Hello!'};
|
||||
},
|
||||
render: function() {
|
||||
var valueLink = this.linkState('value');
|
||||
var handleChange = function(e) {
|
||||
valueLink.requestChange(e.target.value);
|
||||
};
|
||||
return <input type="text" value={valueLink.value} onChange={handleChange} />;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The `valueLink` prop is also quite simple. It simply handles the `onChange` event and calls `this.props.valueLink.requestChange()` and also uses `this.props.valueLink.value` instead of `this.props.value`. That's it!
|
||||
46
docs/docs/09.3-class-name-manipulation.md
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
id: class-name-manipulation
|
||||
title: Class Name Manipulation
|
||||
layout: docs
|
||||
permalink: class-name-manipulation.html
|
||||
prev: two-way-binding-helpers.html
|
||||
next: examples.html
|
||||
---
|
||||
|
||||
`classSet()` is a neat utility for easily manipulating the DOM `class` string.
|
||||
|
||||
Here's a common scenario and its solution without `classSet()`:
|
||||
|
||||
```javascript
|
||||
// inside some `<Message />` React component
|
||||
render: function() {
|
||||
var classString = 'message';
|
||||
if (this.props.isImportant) {
|
||||
classString += ' message-important';
|
||||
}
|
||||
if (this.props.isRead) {
|
||||
classString += ' message-read';
|
||||
}
|
||||
// 'message message-important message-read'
|
||||
return <div className={classString}>Great, I'll be there.</div>;
|
||||
}
|
||||
```
|
||||
|
||||
This can quickly get tedious, as assigning class name strings can be hard to read and error-prone. `classSet()` solves this problem:
|
||||
|
||||
```javascript
|
||||
render: function() {
|
||||
var cx = React.addons.classSet;
|
||||
var classes = cx({
|
||||
'message': true,
|
||||
'message-important': this.props.isImportant,
|
||||
'message-read': this.props.isRead
|
||||
});
|
||||
// same final string, but much cleaner
|
||||
return <div className={classes}>Great, I'll be there.</div>;
|
||||
}
|
||||
```
|
||||
|
||||
When using `classSet()`, pass an object with keys of the CSS class names you might or might not need. Truthy values will result in the key being a part of the resulting string.
|
||||
|
||||
No more hacky string concatenations!
|
||||
22
docs/docs/10-examples.md
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
id: examples
|
||||
title: Examples
|
||||
layout: docs
|
||||
permalink: examples.html
|
||||
prev: addons.html
|
||||
---
|
||||
|
||||
### Production Apps
|
||||
|
||||
* All of [Instagram.com](http://instagram.com/) is built on React.
|
||||
* Many components on [Facebook.com](http://www.facebook.com/), including the commenting interface, ads creation flows, and page insights.
|
||||
* [Khan Academy](http://khanacademy.org/) is using React for most new JS development.
|
||||
|
||||
|
||||
### Sample Code
|
||||
|
||||
* We've included [a step-by-step comment box tutorial](./tutorial.html).
|
||||
* [The React starter kit](/react/downloads.html) includes several examples which you can [view online in our GitHub repository](https://github.com/facebook/react/tree/master/examples/).
|
||||
* [React Page](https://github.com/facebook/react-page) is a simple React project creator to get you up-and-running quickly with React. It supports both server-side and client-side rendering, source transform and packaging JSX files using CommonJS modules, and instant reload.
|
||||
* [React one-hour email](https://github.com/petehunt/react-one-hour-email/commits/master) goes step-by-step from a static HTML mock to an interactive email reader (written in just one hour!)
|
||||
* [Rendr + React app template](https://github.com/petehunt/rendr-react-template/) demonstrates how to use React's server rendering capabilities.
|
||||
@@ -1,96 +0,0 @@
|
||||
---
|
||||
id: OUTLINE
|
||||
title: Goals of the documentation
|
||||
layout: docs
|
||||
prev: 09.1-tutorial.html
|
||||
---
|
||||
- Flow of docs should mimic progression of questions a new user would ask
|
||||
- High information density -- assume the reader is adept at JS
|
||||
- Talk about best practices
|
||||
- JSFiddles for all code samples
|
||||
- Provide background for some of the design decisions
|
||||
- Less words less words less words!
|
||||
|
||||
## Outline
|
||||
|
||||
Motivation / Why React?
|
||||
- Declarative (simple)
|
||||
- Components (separation of concerns)
|
||||
- Give it 5 minutes
|
||||
|
||||
Displaying data
|
||||
- Hello world example
|
||||
- Reactive updates
|
||||
- Components are just functions
|
||||
- JSX syntax (link to separate doc?)
|
||||
- JSX gotchas
|
||||
|
||||
Interactivity and dynamic UIs
|
||||
- Click handler example
|
||||
- Event handlers / synthetic events (link to w3c docs)
|
||||
- Under the hood: autoBind and event delegation (IE8 notes)
|
||||
- React is a state machine
|
||||
- How state works
|
||||
- What components should have state?
|
||||
- What should go in state?
|
||||
- What shouldn't go in state?
|
||||
|
||||
Scaling up: using multiple components
|
||||
- Motivation: separate concerns
|
||||
- Composition example
|
||||
- Ownership (and owner vs. parent)
|
||||
- Children
|
||||
- Data flow (one-way data binding)
|
||||
- A note on performance
|
||||
|
||||
Building effective reusable components
|
||||
- You should build a reusable component library (CSS, testing etc)
|
||||
- Prop validation
|
||||
- Transferring props: a shortcut
|
||||
- Mixins
|
||||
- Testing
|
||||
|
||||
Forms
|
||||
|
||||
Working with the browser
|
||||
- The mock DOM
|
||||
- Refs / getDOMNode()
|
||||
- More about refs
|
||||
- Component lifecycle
|
||||
- Browser support and polyfills
|
||||
|
||||
Working with your environment
|
||||
- CDN-hosted React
|
||||
- Using master
|
||||
- In-browser JSX transform
|
||||
- Productionizing: precompiled JSX
|
||||
- Helpful open-source projects
|
||||
|
||||
Integrating with other UI libraries
|
||||
- Using jQuery plugins
|
||||
- Letting jQuery manage React components
|
||||
- Using with Backbone.View
|
||||
- CoffeeScript
|
||||
- Moving from Handlebars to React: an example
|
||||
|
||||
Server / static rendering
|
||||
- Motivation
|
||||
- Simple example
|
||||
- How does it work? (No DOM)
|
||||
- Rendr + React
|
||||
|
||||
Big ideas
|
||||
- Animation
|
||||
- Bootstrap bindings (responsive grids)
|
||||
- Reactive CSS
|
||||
- Web workers
|
||||
- Native views
|
||||
|
||||
Case studies
|
||||
- Comment box tutorial from scratch
|
||||
- From HTML mock to application: React one-hour email
|
||||
- Jordan's LikeToggler example
|
||||
|
||||
Reference
|
||||
- API
|
||||
- DOM differences
|
||||
@@ -44,7 +44,7 @@ In the root directory of the starter kit, create a `helloworld.html` with the fo
|
||||
</html>
|
||||
```
|
||||
|
||||
The XML syntax inside of JavaScript is called JSX; check out the [JSX syntax](syntax.html) to learn more about it. In order to translate it to vanilla JavaScript we use `<script type="text/jsx">` and include `JSXTransformer.js` to actually perform the transformation in the browser.
|
||||
The XML syntax inside of JavaScript is called JSX; check out the [JSX syntax](jsx-in-depth.html) to learn more about it. In order to translate it to vanilla JavaScript we use `<script type="text/jsx">` and include `JSXTransformer.js` to actually perform the transformation in the browser.
|
||||
|
||||
### Separate File
|
||||
|
||||
@@ -84,7 +84,7 @@ The file `build/helloworld.js` is autogenerated whenever you make a change.
|
||||
/** @jsx React.DOM */
|
||||
React.renderComponent(
|
||||
React.DOM.h1(null, 'Hello, world!'),
|
||||
document.getElementyById('example')
|
||||
document.getElementById('example')
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
4
docs/docs/index.html
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
layout: redirect
|
||||
destination: getting-started.html
|
||||
---
|
||||
77
docs/docs/ref-01-top-level-api.md
Normal file
@@ -0,0 +1,77 @@
|
||||
---
|
||||
id: top-level-api
|
||||
title: Top-Level API
|
||||
layout: docs
|
||||
permalink: top-level-api.html
|
||||
next: component-api.html
|
||||
---
|
||||
|
||||
## React
|
||||
|
||||
`React` is the entry point to the React framework. If you're using one of the prebuilt packages it's available as a global; if you're using CommonJS modules you can `require()` it.
|
||||
|
||||
|
||||
### React.DOM
|
||||
|
||||
`React.DOM` provides all of the standard HTML tags needed to build a React app. You generally don't use it directly; instead, just include it as part of the `/** @jsx React.DOM */` docblock.
|
||||
|
||||
|
||||
### React.initializeTouchEvents
|
||||
|
||||
```javascript
|
||||
initializeTouchEvents(boolean shouldUseTouch)
|
||||
```
|
||||
|
||||
Configure React's event system to handle touch events on mobile devices.
|
||||
|
||||
|
||||
### React.createClass
|
||||
|
||||
```javascript
|
||||
function createClass(object specification)
|
||||
```
|
||||
|
||||
Creates a component given a specification. A component implements a `render` method which returns **one single** child. That child may have an arbitrarily deep child structure. One thing that makes components different than standard prototypal classes is that you don't need to call new on them. They are convenience wrappers that construct backing instances (via new) for you.
|
||||
|
||||
For more information about the specification object, see [Component Specs and Lifecycle](component-specs.html).
|
||||
|
||||
|
||||
### React.renderComponent
|
||||
|
||||
```javascript
|
||||
ReactComponent renderComponent(
|
||||
ReactComponent component,
|
||||
DOMElement container,
|
||||
[function callback]
|
||||
)
|
||||
```
|
||||
|
||||
Renders a React component into the DOM in the supplied `container`.
|
||||
|
||||
If the React component was previously rendered into `container`, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React component.
|
||||
|
||||
If the optional callback is provided, it will be executed after the component is rendered or updated.
|
||||
|
||||
|
||||
### React.unmountComponentAtNode
|
||||
|
||||
```javascript
|
||||
unmountComponentAtNode(DOMElement container)
|
||||
```
|
||||
|
||||
Remove a mounted React component from the DOM and clean up its event handlers and state.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> This method was called `React.unmountAndReleaseReactRootNode` until v0.5. It still works in v0.5 but will be removed in future versions.
|
||||
|
||||
|
||||
### React.renderComponentToString
|
||||
|
||||
```javascript
|
||||
renderComponentToString(ReactComponent component, function callback)
|
||||
```
|
||||
|
||||
Render a component to its initial HTML. This should only be used on the server. React will call `callback` with an HTML string when the markup is ready. You can use this method to can generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.
|
||||
|
||||
If you call `React.renderComponent()` on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
|
||||
109
docs/docs/ref-02-component-api.md
Normal file
@@ -0,0 +1,109 @@
|
||||
---
|
||||
id: component-api
|
||||
title: Component API
|
||||
layout: docs
|
||||
permalink: component-api.html
|
||||
prev: top-level-api.html
|
||||
next: component-specs.html
|
||||
---
|
||||
|
||||
## ReactComponent
|
||||
|
||||
Component classses created by `createClass()` return instances of `ReactComponent` when called. Most of the time when you're using React you're either creating or consuming these component objects.
|
||||
|
||||
|
||||
### getDOMNode
|
||||
|
||||
```javascript
|
||||
DOMElement getDOMNode()
|
||||
```
|
||||
|
||||
If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements.
|
||||
|
||||
|
||||
### setProps
|
||||
|
||||
```javascript
|
||||
setProps(object nextProps)
|
||||
```
|
||||
|
||||
When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with `renderComponent()`. Simply call `setProps()` to change its properties and trigger a re-render.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> This method can only be called on a root-level component. That is, it's only available on the component passed directly to `renderComponent()` and none of its children. If you're inclined to use `setProps()` on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in `render()`.
|
||||
|
||||
|
||||
### replaceProps
|
||||
|
||||
```javascript
|
||||
replaceProps(object nextProps)
|
||||
```
|
||||
|
||||
Like `setProps()` but deletes any pre-existing props instead of merging the two objects.
|
||||
|
||||
|
||||
### transferPropsTo
|
||||
|
||||
```javascript
|
||||
ReactComponent transferPropsTo(ReactComponent targetComponent)
|
||||
```
|
||||
|
||||
Transfer properties from this component to a target component that have not already been set on the target component. After the props are updated, `targetComponent` is returned as a convenience. This function is useful when creating simple HTML-like components:
|
||||
|
||||
```javascript
|
||||
var Avatar = React.createClass({
|
||||
render: function() {
|
||||
return this.transferPropsTo(
|
||||
<img src={"/avatars/" + this.props.userId + ".png"} userId={null} />
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// <Avatar userId={17} width={200} height={200} />
|
||||
```
|
||||
|
||||
Properties that are specified directly on the target component instance (such as `src` and `userId` in the above example) will not be overwritten by `transferPropsTo`.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> Use `transferPropsTo` with caution; it encourages tight coupling and makes it easy to accidentally introduce implicit dependencies between components. When in doubt, it's safer to explicitly copy the properties that you need onto the child component.
|
||||
|
||||
|
||||
### setState
|
||||
|
||||
```javascript
|
||||
setState(object nextState[, function callback])
|
||||
```
|
||||
|
||||
Merges nextState with the current state. This is the primary method you use to trigger UI updates from event handlers and server request callbacks. In addition, you can supply an optional callback function that is executed once `setState` is completed.
|
||||
|
||||
> Notes:
|
||||
>
|
||||
> *NEVER* mutate `this.state` directly, as calling `setState()` afterwards may replace the mutation you made. Treat `this.state` as if it were immutable.
|
||||
>
|
||||
> `setState()` does not immediately mutate `this.state` but creates a pending state transition. Accessing `this.state` after calling this method can potentially return the existing value.
|
||||
>
|
||||
> There is no guarantee of synchronous operation of calls to `setState` and calls may be batched for performance gains.
|
||||
|
||||
|
||||
### replaceState
|
||||
|
||||
```javascript
|
||||
replaceState(object nextState[, function callback])
|
||||
```
|
||||
|
||||
Like `setState()` but deletes any pre-existing state keys that are not in nextState.
|
||||
|
||||
|
||||
### forceUpdate()
|
||||
|
||||
```javascript
|
||||
forceUpdate([function callback])
|
||||
```
|
||||
|
||||
If your `render()` method reads from something other than `this.props` or `this.state`, you'll need to tell React when it needs to re-run `render()` by calling `forceUpdate()`. You'll also need to call `forceUpdate()` if you mutate `this.state` directly.
|
||||
|
||||
Calling `forceUpdate()` will cause `render()` to be called on the component and its children, but React will still only update the DOM if the markup changes.
|
||||
|
||||
Normally you should try to avoid all uses of `forceUpdate()` and only read from `this.props` and `this.state` in `render()`. This makes your application much simpler and more efficient.
|
||||
176
docs/docs/ref-03-component-specs.md
Normal file
@@ -0,0 +1,176 @@
|
||||
---
|
||||
id: component-specs
|
||||
title: Component Specs and Lifecycle
|
||||
layout: docs
|
||||
permalink: component-specs.html
|
||||
prev: component-api.html
|
||||
next: tags-and-attributes.html
|
||||
---
|
||||
|
||||
## Component Specifications
|
||||
|
||||
When creating a component class by invoking `React.createClass()`, you should provide a specification object that contains a `render` method and can optionally contain other lifecycle methods described here.
|
||||
|
||||
|
||||
### render
|
||||
|
||||
```javascript
|
||||
ReactComponent render()
|
||||
```
|
||||
|
||||
The `render()` method is required.
|
||||
|
||||
When called, it should examine `this.props` and `this.state` and return a single child component. This child component can be either a native DOM component (such as `<div>`) or another composite component that you've defined yourself.
|
||||
|
||||
The `render()` function should be *pure*, meaning that it does not modify component state, it returns the same result each time it's invoked, and it does not read from or write to the DOM or otherwise interact with the browser (e.g., by using `setTimeout`). If you need to interact with the browser, perform your work in `componentDidMount()` or the other lifecycle methods instead. Keeping `render()` pure makes server rendering more practical and makes components easier to think about.
|
||||
|
||||
|
||||
### getInitialState
|
||||
|
||||
```javascript
|
||||
object getInitialState()
|
||||
```
|
||||
|
||||
Invoked once before the component is mounted. The return value will be used as the initial value of `this.state`.
|
||||
|
||||
|
||||
### getDefaultProps
|
||||
|
||||
```javascript
|
||||
object getDefaultProps()
|
||||
```
|
||||
|
||||
Invoked once when the component is mounted. Values in the mapping will be set on `this.props` if that prop is not specified by the parent component (i.e. using an `in` check).
|
||||
|
||||
This method is invoked before `getInitialState` and therefore cannot rely on `this.state` or use `this.setState`.
|
||||
|
||||
|
||||
### propTypes
|
||||
|
||||
```javascript
|
||||
object propTypes
|
||||
```
|
||||
|
||||
The `propTypes` object allows you to validate props being passed to your components. For more information about `propTypes`, see [Reusable Components](reusable-components.html).
|
||||
|
||||
<!-- TODO: Document propTypes here directly. -->
|
||||
|
||||
|
||||
### mixins
|
||||
|
||||
```javascript
|
||||
array mixins
|
||||
```
|
||||
|
||||
The `mixins` array allows you to use mixins to share behavior among multiple components. For more information about mixins, see [Reusable Components](reusable-components.html).
|
||||
|
||||
<!-- TODO: Document mixins here directly. -->
|
||||
|
||||
|
||||
## Lifecycle Methods
|
||||
|
||||
Various methods are executed at specific points in a component's lifecycle.
|
||||
|
||||
|
||||
### Mounting: componentWillMount
|
||||
|
||||
```javascript
|
||||
componentWillMount()
|
||||
```
|
||||
|
||||
Invoked immediately before rendering occurs. If you call `setState` within this method, `render()` will see the updated state and will be executed only once despite the state change.
|
||||
|
||||
|
||||
### Mounting: componentDidMount
|
||||
|
||||
```javascript
|
||||
componentDidMount(DOMElement rootNode)
|
||||
```
|
||||
|
||||
Invoked immediately after rendering occurs. At this point in the lifecycle, the component has a DOM representation which you can access via the `rootNode` argument or by calling `this.getDOMNode()`.
|
||||
|
||||
If you want to integrate with other JavaScript frameworks, set timers using `setTimeout` or `setInterval`, or send AJAX requests, perform those operations in this method.
|
||||
|
||||
|
||||
### Updating: componentWillReceiveProps
|
||||
|
||||
```javascript
|
||||
componentWillReceiveProps(object nextProps)
|
||||
```
|
||||
|
||||
Invoked when a component is receiving new props. This method is not called for the initial render.
|
||||
|
||||
Use this as an opportunity to react to a prop transition before `render()` is called by updating the state using `this.setState()`. The old props can be accessed via `this.props`. Calling `this.setState()` within this function will not trigger an additional render.
|
||||
|
||||
```javascript
|
||||
componentWillReceiveProps: function(nextProps) {
|
||||
this.setState({
|
||||
likesIncreasing: nextProps.likeCount > this.props.likeCount
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
> Note:
|
||||
>
|
||||
> There is no analogous method `componentWillReceiveState`. An incoming prop transition may cause a state change, but the opposite is not true. If you need to perform operations in response to a state change, use `componentWillUpdate`.
|
||||
|
||||
|
||||
### Updating: shouldComponentUpdate
|
||||
|
||||
```javascript
|
||||
boolean shouldComponentUpdate(object nextProps, object nextState)
|
||||
```
|
||||
|
||||
Invoked before rendering when new props or state are being received. This method is not called for the initial render or when `forceUpdate` is used.
|
||||
|
||||
Use this as an opportunity to `return false` when you're certain that the
|
||||
transition to the new props and state will not require a component update.
|
||||
|
||||
```javascript
|
||||
shouldComponentUpdate: function(nextProps, nextState) {
|
||||
return !equal(nextProps, this.props) || !equal(nextState, this.state);
|
||||
}
|
||||
```
|
||||
|
||||
If `shouldComponentUpdate` returns false, then `render()` will be completely skipped until the next state change. (In addition, `componentWillUpdate` and `componentDidUpdate` will not be called.)
|
||||
|
||||
By default, `shouldComponentUpdate` always returns true to prevent subtle bugs when `state` is mutated in place, but if you are careful to always treat `state` as immutable and to read only from `props` and `state` in `render()` then you can override `shouldComponentUpdate` with an implementation that compares the old props and state to their replacements.
|
||||
|
||||
If performance is a bottleneck, especially with dozens or hundreds of components, use `shouldComponentUpdate` to speed up your app.
|
||||
|
||||
|
||||
### Updating: componentWillUpdate
|
||||
|
||||
```javascript
|
||||
componentWillUpdate(object nextProps, object nextState)
|
||||
```
|
||||
|
||||
Invoked immediately before rendering when new props or state are being received. This method is not called for the initial render.
|
||||
|
||||
Use this as an opportunity to perform preparation before an update occurs.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> You *cannot* use `this.setState()` in this method. If you need to update state in response to a prop change, use `componentWillReceiveProps` instead.
|
||||
|
||||
|
||||
### Updating: componentDidUpdate
|
||||
|
||||
```javascript
|
||||
componentDidUpdate(object prevProps, object prevState, DOMElement rootNode)
|
||||
```
|
||||
|
||||
Invoked immediately after updating occurs. This method is not called for the initial render.
|
||||
|
||||
Use this as an opportunity to operate on the DOM when the component has been updated.
|
||||
|
||||
|
||||
### Unmounting: componentWillUnmount
|
||||
|
||||
```javascript
|
||||
componentWillUnmount()
|
||||
```
|
||||
|
||||
Invoked immediately before a component is unmounted from the DOM.
|
||||
|
||||
Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM elements that were created in `componentDidMount`.
|
||||
68
docs/docs/ref-04-tags-and-attributes.md
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: tags-and-attributes
|
||||
title: Tags and Attributes
|
||||
layout: docs
|
||||
permalink: tags-and-attributes.html
|
||||
prev: component-specs.html
|
||||
next: events.html
|
||||
---
|
||||
|
||||
## Supported Tags
|
||||
|
||||
React attempts to support all common elements. If you need an element that isn't listed here, please file an issue.
|
||||
|
||||
The following elements are supported:
|
||||
|
||||
|
||||
### HTML Elements
|
||||
|
||||
```
|
||||
a abbr address area article aside audio b base bdi bdo big blockquote body br
|
||||
button canvas caption cite code col colgroup data datalist dd del details dfn
|
||||
div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6
|
||||
head header hr html i iframe img input ins kbd keygen label legend li link main
|
||||
map mark menu menuitem meta meter nav noscript object ol optgroup option output
|
||||
p param pre progress q rp rt ruby s samp script section select small source
|
||||
span strong style sub summary sup table tbody td textarea tfoot th thead time
|
||||
title tr track u ul var video wbr
|
||||
```
|
||||
|
||||
### SVG elements
|
||||
|
||||
```
|
||||
circle g line path polyline rect svg text
|
||||
```
|
||||
|
||||
|
||||
## Supported Attributes
|
||||
|
||||
React supports all `data-*` and `aria-*` attributes as well as every attribute in the following lists.
|
||||
|
||||
> Note:
|
||||
>
|
||||
> All attributes are camel-cased and the attributes `class` and `for` are `className` and `htmlFor`, respectively, to match the DOM API specification.
|
||||
|
||||
For a list of events, see [Supported Events](events.html).
|
||||
|
||||
### HTML Attributes
|
||||
|
||||
```
|
||||
accept accessKey action allowFullScreen allowTransparency alt autoCapitalize
|
||||
autoComplete autoFocus autoPlay cellPadding cellSpacing charSet checked
|
||||
className colSpan content contentEditable contextMenu controls data dateTime
|
||||
dir disabled draggable encType form frameBorder height hidden href htmlFor
|
||||
httpEquiv icon id label lang list max maxLength method min multiple name
|
||||
pattern placeholder poster preload radioGroup readOnly rel required role
|
||||
rowSpan scrollLeft scrollTop selected size spellCheck src step style tabIndex
|
||||
target title type value width wmode
|
||||
```
|
||||
|
||||
In addition, the non-standard `autoCapitalize` attribute is supported for Mobile Safari.
|
||||
|
||||
### SVG Attributes
|
||||
|
||||
```
|
||||
cx cy d fill fx fy gradientTransform gradientUnits offset points r rx ry
|
||||
spreadMethod stopColor stopOpacity stroke strokeLinecap strokeWidth transform
|
||||
version viewBox x1 x2 x y1 y2 y
|
||||
```
|
||||
186
docs/docs/ref-05-events.md
Normal file
@@ -0,0 +1,186 @@
|
||||
---
|
||||
id: events
|
||||
title: Event System
|
||||
layout: docs
|
||||
permalink: events.html
|
||||
prev: tags-and-attributes.html
|
||||
next: dom-differences.html
|
||||
---
|
||||
|
||||
## SyntheticEvent
|
||||
|
||||
Your event handlers will be passed instances of `SyntheticEvent`, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event, including `stopPropagation()` and `preventDefault()`, except the events work identically across all browsers.
|
||||
|
||||
If you find that you need the underlying browser event for some reason, simply use the `nativeEvent` attribute to get it. Every `SyntheticEvent` object has the following attributes:
|
||||
|
||||
```javascript
|
||||
boolean bubbles
|
||||
boolean cancelable
|
||||
DOMEventTarget currentTarget
|
||||
boolean defaultPrevented
|
||||
Number eventPhase
|
||||
boolean isTrusted
|
||||
DOMEvent nativeEvent
|
||||
void preventDefault()
|
||||
void stopPropagation()
|
||||
DOMEventTarget target
|
||||
Date timeStamp
|
||||
String type
|
||||
```
|
||||
|
||||
|
||||
## Supported Events
|
||||
|
||||
React normalizes events so that they have consistent properties across
|
||||
different browsers.
|
||||
|
||||
|
||||
### Clipboard Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onCopy onCut onPaste
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
DOMDataTransfer clipboardData
|
||||
```
|
||||
|
||||
|
||||
### Keyboard Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onKeyDown onKeyPress onKeyUp
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
boolean altKey
|
||||
String char
|
||||
boolean ctrlKey
|
||||
String key
|
||||
String locale
|
||||
Number location
|
||||
boolean metaKey
|
||||
boolean repeat
|
||||
boolean shiftKey
|
||||
```
|
||||
|
||||
|
||||
### Focus Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onFocus onBlur
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
DOMEventTarget relatedTarget
|
||||
```
|
||||
|
||||
|
||||
### Form Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onChange onInput onSubmit
|
||||
```
|
||||
|
||||
For more information about the onChange event, see [Forms](forms.html).
|
||||
|
||||
|
||||
### Mouse Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onClick onDoubleClick onDrag onDragEnd onDragEnter onDragExit onDragLeave
|
||||
onDragOver onDragStart onDrop onMouseDown onMouseEnter onMouseLeave
|
||||
onMouseMove onMouseUp
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
boolean altKey
|
||||
Number button
|
||||
Number buttons
|
||||
Number clientX
|
||||
Number clientY
|
||||
boolean ctrlKey
|
||||
boolean metaKey
|
||||
Number pageX
|
||||
Number pageY
|
||||
DOMEventTarget relatedTarget
|
||||
Number screenX
|
||||
Number screenY
|
||||
boolean shiftKey
|
||||
```
|
||||
|
||||
|
||||
### Touch events
|
||||
|
||||
To enable touch events, call `React.initializeTouchEvents(true)` before
|
||||
rendering any component.
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onTouchCancel onTouchEnd onTouchMove onTouchStart
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
boolean altKey
|
||||
DOMTouchList changedTouches
|
||||
boolean ctrlKey
|
||||
boolean metaKey
|
||||
boolean shiftKey
|
||||
DOMTouchList targetTouches
|
||||
DOMTouchList touches
|
||||
```
|
||||
|
||||
|
||||
### UI Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onScroll
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
Number detail
|
||||
DOMAbstractView view
|
||||
```
|
||||
|
||||
|
||||
### Wheel Events
|
||||
|
||||
Event names:
|
||||
|
||||
```
|
||||
onWheel
|
||||
```
|
||||
|
||||
Properties:
|
||||
|
||||
```javascript
|
||||
Number deltaX
|
||||
Number deltaMode
|
||||
Number deltaY
|
||||
Number deltaZ
|
||||
```
|
||||
14
docs/docs/ref-06-dom-differences.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
id: dom-differences
|
||||
title: DOM Differences
|
||||
layout: docs
|
||||
permalink: dom-differences.html
|
||||
prev: events.html
|
||||
---
|
||||
|
||||
React has implemented a browser-independent events and DOM system for performance and cross-browser compatibility reasons. We took the opportunity to clean up a few rough edges in browser DOM implementations.
|
||||
|
||||
* All DOM properties and attributes (including event handlers) should be camelCased to be consistent with standard JavaScript style. We intentionally break with the spec here since the spec is inconsistent.
|
||||
* The `style` attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM `style` JavaScript property, is more efficient, and prevents XSS security holes.
|
||||
* All event objects conform to the W3C spec, and all events (including submit) bubble correctly per the W3C spec. See [Event System](events.html) for more details.
|
||||
* The `onChange` event behaves as you would expect it to: whenever a form field is changed this event is fired rather than inconsistently on blur. We intentionally break from existing browser behavior because `onChange` is a misnomer for its behavior and React relies on this event to react to user input in real time. See [Forms](forms.html) for more details.
|
||||
4
docs/docs/reference.html
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
layout: redirect
|
||||
destination: top-level-api.html
|
||||
---
|
||||
@@ -65,7 +65,7 @@ Let's build the `CommentBox` component, which is just a simple `<div>`:
|
||||
var CommentBox = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
Hello, world! I am a CommentBox.
|
||||
</div>
|
||||
);
|
||||
@@ -99,7 +99,7 @@ React.renderComponent(
|
||||
);
|
||||
```
|
||||
|
||||
Its use is optional but we've found JSX syntax easier to use than plain JavaScript. Read more on the [JSX Syntax article](syntax.html).
|
||||
Its use is optional but we've found JSX syntax easier to use than plain JavaScript. Read more on the [JSX Syntax article](jsx-in-depth.html).
|
||||
|
||||
#### What's going on
|
||||
|
||||
@@ -107,7 +107,7 @@ We pass some methods in a JavaScript object to `React.createClass()` to create a
|
||||
|
||||
The `<div>` tags are not actual DOM nodes; they are instantiations of React `div` components. You can think of these as markers or pieces of data that React knows how to handle. React is **safe**. We are not generating HTML strings so XSS protection is the default.
|
||||
|
||||
You do not have to return basic HTML. You can return a tree of components that you (or someone else built). This is what makes React **composable**: a key tenet of maintainable frontends.
|
||||
You do not have to return basic HTML. You can return a tree of components that you (or someone else) built. This is what makes React **composable**: a key tenet of maintainable frontends.
|
||||
|
||||
`React.renderComponent()` instantiates the root component, starts the framework, and injects the markup into a raw DOM element, provided as the second argument.
|
||||
|
||||
@@ -120,7 +120,7 @@ Let's build skeletons for `CommentList` and `CommentForm` which will, again, be
|
||||
var CommentList = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentList">
|
||||
<div className="commentList">
|
||||
Hello, world! I am a CommentList.
|
||||
</div>
|
||||
);
|
||||
@@ -130,7 +130,7 @@ var CommentList = React.createClass({
|
||||
var CommentForm = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentForm">
|
||||
<div className="commentForm">
|
||||
Hello, world! I am a CommentForm.
|
||||
</div>
|
||||
);
|
||||
@@ -145,7 +145,7 @@ Next, update the `CommentBox` component to use its new friends:
|
||||
var CommentBox = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList />
|
||||
<CommentForm />
|
||||
@@ -166,7 +166,7 @@ Let's create our third component, `Comment`. We will want to pass it the author
|
||||
var CommentList = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentList">
|
||||
<div className="commentList">
|
||||
<Comment author="Pete Hunt">This is one comment</Comment>
|
||||
<Comment author="Jordan Walke">This is *another* comment</Comment>
|
||||
</div>
|
||||
@@ -186,8 +186,8 @@ Let's create the Comment component. It will read the data passed to it from the
|
||||
var Comment = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="comment">
|
||||
<h2 class="commentAuthor">
|
||||
<div className="comment">
|
||||
<h2 className="commentAuthor">
|
||||
{this.props.author}
|
||||
</h2>
|
||||
{this.props.children}
|
||||
@@ -203,7 +203,17 @@ By surrounding a JavaScript expression in braces inside JSX (as either an attrib
|
||||
|
||||
Markdown is a simple way to format your text inline. For example, surrounding text with asterisks will make it emphasized.
|
||||
|
||||
First, add the third-party **Showdown** library to your application. This is a JavaScript library which takes Markdown text and converts it to raw HTML. This requires a script tag in your head (which we have already included in the React playground).
|
||||
First, add the third-party **Showdown** library to your application. This is a JavaScript library which takes Markdown text and converts it to raw HTML. This requires a script tag in your head (which we have already included in the React playground):
|
||||
|
||||
```html{6}
|
||||
<!-- template.html -->
|
||||
<head>
|
||||
<title>Hello React</title>
|
||||
<script src="http://fb.me/react-{{site.react_version}}.js"></script>
|
||||
<script src="http://fb.me/JSXTransformer-{{site.react_version}}.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js"></script>
|
||||
</head>
|
||||
```
|
||||
|
||||
Next, let's convert the comment text to Markdown and output it:
|
||||
|
||||
@@ -213,8 +223,8 @@ var converter = new Showdown.converter();
|
||||
var Comment = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="comment">
|
||||
<h2 class="commentAuthor">
|
||||
<div className="comment">
|
||||
<h2 className="commentAuthor">
|
||||
{this.props.author}
|
||||
</h2>
|
||||
{converter.makeHtml(this.props.children.toString())}
|
||||
@@ -237,8 +247,8 @@ var Comment = React.createClass({
|
||||
render: function() {
|
||||
var rawMarkup = converter.makeHtml(this.props.children.toString());
|
||||
return (
|
||||
<div class="comment">
|
||||
<h2 class="commentAuthor">
|
||||
<div className="comment">
|
||||
<h2 className="commentAuthor">
|
||||
{this.props.author}
|
||||
</h2>
|
||||
<span dangerouslySetInnerHTML={{"{{"}}__html: rawMarkup}} />
|
||||
@@ -271,7 +281,7 @@ We need to get this data into `CommentList` in a modular way. Modify `CommentBox
|
||||
var CommentBox = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.props.data} />
|
||||
<CommentForm />
|
||||
@@ -296,7 +306,7 @@ var CommentList = React.createClass({
|
||||
return <Comment author={comment.author}>{comment.text}</Comment>;
|
||||
});
|
||||
return (
|
||||
<div class="commentList">
|
||||
<div className="commentList">
|
||||
{commentNodes}
|
||||
</div>
|
||||
);
|
||||
@@ -314,7 +324,7 @@ Let's replace the hard-coded data with some dynamic data from the server. We wil
|
||||
// tutorial11.js
|
||||
React.renderComponent(
|
||||
<CommentBox url="comments.json" />,
|
||||
document.getElementById('example')
|
||||
document.getElementById('content')
|
||||
);
|
||||
```
|
||||
|
||||
@@ -336,7 +346,7 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm />
|
||||
@@ -359,7 +369,7 @@ When the component is first created, we want to GET some JSON from the server an
|
||||
]
|
||||
```
|
||||
|
||||
We will use jQuery 1.5 to help make an asynchronous request to the server.
|
||||
We will use jQuery to help make an asynchronous request to the server.
|
||||
|
||||
Note: because this is becoming an AJAX application you'll need to develop your app using a web server rather than as a file sitting on your file system. The easiest way to do this is to run `python -m SimpleHTTPServer` in your application's directory.
|
||||
|
||||
@@ -369,8 +379,6 @@ var CommentBox = React.createClass({
|
||||
getInitialState: function() {
|
||||
$.ajax({
|
||||
url: 'comments.json',
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -379,7 +387,7 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm />
|
||||
@@ -397,8 +405,6 @@ var CommentBox = React.createClass({
|
||||
loadCommentsFromServer: function() {
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -409,14 +415,11 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
componentWillMount: function() {
|
||||
this.loadCommentsFromServer();
|
||||
setInterval(
|
||||
this.loadCommentsFromServer.bind(this),
|
||||
this.props.pollInterval
|
||||
);
|
||||
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm />
|
||||
@@ -426,27 +429,27 @@ var CommentBox = React.createClass({
|
||||
});
|
||||
|
||||
React.renderComponent(
|
||||
<CommentBox url="comments.json" pollInterval={5000} />,
|
||||
<CommentBox url="comments.json" pollInterval={2000} />,
|
||||
document.getElementById('content')
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 5 seconds after that. Try running this in your browser and changing the `comments.json` file; within 5 seconds, the changes will show!
|
||||
All we have done here is move the AJAX call to a separate method and call it when the component is first loaded and every 2 seconds after that. Try running this in your browser and changing the `comments.json` file; within 2 seconds, the changes will show!
|
||||
|
||||
### Adding new comments
|
||||
|
||||
Now it's time to build the form. Our `CommentForm` component should ask the user for their name and comment text and send a request to the server to save the comment.
|
||||
|
||||
```javascript{5-8}
|
||||
```javascript{5-9}
|
||||
// tutorial15.js
|
||||
var CommentForm = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
<form class="commentForm">
|
||||
<form className="commentForm">
|
||||
<input type="text" placeholder="Your name" />
|
||||
<input type="text" placeholder="Say something..." />
|
||||
<input type="submit" />
|
||||
<input type="submit" value="Post" />
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -471,14 +474,14 @@ var CommentForm = React.createClass({
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<form class="commentForm" onSubmit={this.handleSubmit}>
|
||||
<form className="commentForm" onSubmit={this.handleSubmit}>
|
||||
<input type="text" placeholder="Your name" ref="author" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Say something..."
|
||||
ref="text"
|
||||
/>
|
||||
<input type="submit" />
|
||||
<input type="submit" value="Post" />
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -489,7 +492,7 @@ var CommentForm = React.createClass({
|
||||
|
||||
React attaches event handlers to components using a camelCase naming convention. We attach an `onSubmit` handler to the form that clears the form fields when the form is submitted with valid input.
|
||||
|
||||
We always return `false` from the event handler to prevent the browser's default action of submitting the form. (If you prefer, you can instead take the event as an argument and call `preventDefault()` on it – read more about [event handling](event-handling.html).)
|
||||
We always return `false` from the event handler to prevent the browser's default action of submitting the form. (If you prefer, you can instead take the event as an argument and call `preventDefault()` on it.)
|
||||
|
||||
##### Refs
|
||||
|
||||
@@ -507,8 +510,6 @@ var CommentBox = React.createClass({
|
||||
loadCommentsFromServer: function() {
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -522,14 +523,11 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
componentWillMount: function() {
|
||||
this.loadCommentsFromServer();
|
||||
setInterval(
|
||||
this.loadCommentsFromServer.bind(this),
|
||||
this.props.pollInterval
|
||||
);
|
||||
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm
|
||||
@@ -556,14 +554,14 @@ var CommentForm = React.createClass({
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<form class="commentForm" onSubmit={this.handleSubmit}>
|
||||
<form className="commentForm" onSubmit={this.handleSubmit}>
|
||||
<input type="text" placeholder="Your name" ref="author" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Say something..."
|
||||
ref="text"
|
||||
/>
|
||||
<input type="submit" />
|
||||
<input type="submit" value="Post" />
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -578,8 +576,6 @@ var CommentBox = React.createClass({
|
||||
loadCommentsFromServer: function() {
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -588,9 +584,8 @@ var CommentBox = React.createClass({
|
||||
handleCommentSubmit: function(comment) {
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
type: 'POST',
|
||||
data: comment,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -601,14 +596,11 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
componentWillMount: function() {
|
||||
this.loadCommentsFromServer();
|
||||
setInterval(
|
||||
this.loadCommentsFromServer.bind(this),
|
||||
this.props.pollInterval
|
||||
);
|
||||
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm
|
||||
@@ -630,8 +622,6 @@ var CommentBox = React.createClass({
|
||||
loadCommentsFromServer: function() {
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -639,13 +629,12 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
handleCommentSubmit: function(comment) {
|
||||
var comments = this.state.data;
|
||||
comments.push(comment);
|
||||
this.setState({data: comments});
|
||||
var newComments = comments.concat([comment]);
|
||||
this.setState({data: newComments});
|
||||
$.ajax({
|
||||
url: this.props.url,
|
||||
type: 'POST',
|
||||
data: comment,
|
||||
dataType: 'json',
|
||||
mimeType: 'textPlain',
|
||||
success: function(data) {
|
||||
this.setState({data: data});
|
||||
}.bind(this)
|
||||
@@ -656,14 +645,11 @@ var CommentBox = React.createClass({
|
||||
},
|
||||
componentWillMount: function() {
|
||||
this.loadCommentsFromServer();
|
||||
setInterval(
|
||||
this.loadCommentsFromServer.bind(this),
|
||||
this.props.pollInterval
|
||||
);
|
||||
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<div class="commentBox">
|
||||
<div className="commentBox">
|
||||
<h1>Comments</h1>
|
||||
<CommentList data={this.state.data} />
|
||||
<CommentForm
|
||||
@@ -677,4 +663,4 @@ var CommentBox = React.createClass({
|
||||
|
||||
### Congrats!
|
||||
|
||||
You have just built a comment box in a few simple steps. Learn more about React in the [reference](syntax.html) or start hacking! Good luck!
|
||||
You have just built a comment box in a few simple steps. Learn more about [why to use React](why-react.html), or dive into the [API reference](top-level-api.html) and start hacking! Good luck!
|
||||
|
||||
@@ -28,13 +28,29 @@ The uncompressed, development version of React core with inline documentation.
|
||||
<script src="http://fb.me/react-{{site.react_version}}.js"></script>
|
||||
```
|
||||
|
||||
#### <a href="http://fb.me/react-with-addons-{{site.react_version}}.min.js">React With Add-Ons {{site.react_version}} (production)</a>
|
||||
The compressed, production version of React with [add-ons](/react/docs/addons.html).
|
||||
|
||||
```html
|
||||
<script src="http://fb.me/react-with-addons-{{site.react_version}}.min.js"></script>
|
||||
```
|
||||
|
||||
#### <a href="http://fb.me/react-with-addons-{{site.react_version}}.js">React With Add-Ons {{site.react_version}} (development)</a>
|
||||
The uncompressed, development version of React with [add-ons](/react/docs/addons.html).
|
||||
|
||||
```html
|
||||
<script src="http://fb.me/react-with-addons-{{site.react_version}}.js"></script>
|
||||
```
|
||||
|
||||
#### <a href="http://fb.me/JSXTransformer-{{site.react_version}}.js">JSX Transform</a>
|
||||
The JSX transformer used to support [XML syntax](/react/docs/syntax.html) in JavaScript.
|
||||
The JSX transformer used to support [XML syntax](/react/docs/jsx-in-depth.html) in JavaScript.
|
||||
|
||||
```html
|
||||
<script src="http://fb.me/JSXTransformer-{{site.react_version}}.js"></script>
|
||||
```
|
||||
|
||||
All scripts are also available via [CDNJS](http://cdnjs.com/#react).
|
||||
|
||||
## Bower
|
||||
|
||||
```sh
|
||||
|
||||
BIN
docs/img/blog/dog-tutorial.png
Normal file
|
After Width: | Height: | Size: 59 KiB |
BIN
docs/img/blog/genesis_skeleton.png
Normal file
|
After Width: | Height: | Size: 168 KiB |
BIN
docs/img/blog/guess_filter.jpg
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
docs/img/blog/landoflisp.png
Normal file
|
After Width: | Height: | Size: 156 KiB |
BIN
docs/img/blog/markdown_refactor.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
docs/img/blog/quiztime.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/img/blog/react-hackathon.jpg
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
docs/img/blog/react-page.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/img/blog/react-php.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
docs/img/blog/steve_reverse.gif
Normal file
|
After Width: | Height: | Size: 5.4 MiB |
BIN
docs/img/blog/thinking-in-react-components.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
docs/img/blog/thinking-in-react-mock.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/img/blog/turboreact.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
docs/img/blog/tutsplus.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
docs/img/blog/unite.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
docs/img/blog/wolfenstein_react.png
Normal file
|
After Width: | Height: | Size: 121 KiB |
BIN
docs/img/blog/xoxo2013.png
Normal file
|
After Width: | Height: | Size: 246 KiB |
@@ -7,23 +7,25 @@ id: home
|
||||
<section class="light home-section">
|
||||
<div class="marketing-row">
|
||||
<div class="marketing-col">
|
||||
<h3>Declarative</h3>
|
||||
<h3>Just the UI</h3>
|
||||
<p>
|
||||
React uses a declarative paradigm that makes it easier to reason about
|
||||
your application.
|
||||
Lots of people use React as the V in MVC.
|
||||
Since React makes no assumptions about the rest of your technology stack,
|
||||
it's easy to try it out on a small feature in an existing project.
|
||||
</p>
|
||||
</div>
|
||||
<div class="marketing-col">
|
||||
<h3>Efficient</h3>
|
||||
<h3>Virtual DOM</h3>
|
||||
<p>
|
||||
React computes the minimal set of changes necessary to keep your DOM
|
||||
up-to-date.
|
||||
React uses a <i>virtual DOM</i> diff implementation for ultra-high performance. It can also
|
||||
render on the server using Node.js — no heavy browser DOM required.
|
||||
</p>
|
||||
</div>
|
||||
<div class="marketing-col">
|
||||
<h3>Flexible</h3>
|
||||
<h3>Data flow</h3>
|
||||
<p>
|
||||
React works with the libraries and frameworks that you already know.
|
||||
React implements one-way reactive data flow which reduces boilerplate and is
|
||||
easier to reason about than traditional data binding.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,7 +62,7 @@ id: home
|
||||
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.
|
||||
delegation.
|
||||
</p>
|
||||
<div id="todoExample"></div>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ id: jsx-compiler
|
||||
<div class="jsxCompiler">
|
||||
<h1>JSX Compiler</h1>
|
||||
<p>
|
||||
This tool demonstrates how <a href="/react/docs/syntax.html">JSX syntax</a>
|
||||
This tool demonstrates how <a href="/react/docs/jsx-in-depth.html">JSX syntax</a>
|
||||
is desguared into native JavaScript.
|
||||
</p>
|
||||
<div id="jsxCompiler"></div>
|
||||
|
||||
@@ -6,9 +6,13 @@ id: support
|
||||
|
||||
**React** is worked on full-time by Facebook's product infrastructure and Instagram's user interface engineering teams. They're often around and available for questions.
|
||||
|
||||
## Stack Overflow
|
||||
|
||||
Many members of the community use Stack Overflow to ask questions. Read through the [existing questions](http://stackoverflow.com/questions/tagged/reactjs) tagged with **reactjs** or [ask your own](http://stackoverflow.com/questions/ask)!
|
||||
|
||||
## Google Groups mailing list
|
||||
|
||||
<a href="http://groups.google.com/group/reactjs" target="_blank">The **reactjs** Google Group</a> is the best place to ask questions and find answers.
|
||||
<a href="http://groups.google.com/group/reactjs" target="_blank">The **reactjs** Google Group</a> is also a good place to ask questions and find answers.
|
||||
|
||||
## IRC
|
||||
|
||||
|
||||
13
docs/tips/01-introduction.md
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
id: introduction
|
||||
title: Introduction
|
||||
layout: tips
|
||||
permalink: introduction.html
|
||||
next: inline-styles.html
|
||||
---
|
||||
|
||||
The React tips section provides bite-sized information that can answer lots of questions you might have and warn you against common pitfalls.
|
||||
|
||||
## Contributing
|
||||
|
||||
Submit a pull request to the [React repository](https://github.com/facebook/react) following the [current tips](https://github.com/facebook/react/tree/master/docs) entries' style. If you have a recipe that needs review prior to submitting a PR you can find help in the [#reactjs channel on freenode](irc://chat.freenode.net/reactjs) or the [reactjs Google group](http://groups.google.com/group/reactjs). Also, check the [Tips Wiki](https://github.com/facebook/react/wiki/Tips-(Previously-Cookbook)) for entries in-progress and general guidelines on writing React tips.
|
||||
24
docs/tips/02-inline-styles.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
id: inline-styles
|
||||
title: Inline Styles
|
||||
layout: tips
|
||||
permalink: inline-styles.html
|
||||
next: if-else-in-JSX.html
|
||||
prev: introduction.html
|
||||
---
|
||||
|
||||
In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version of the style name, and whose value is the style's value, usually a string ([more on that later](/react/tips/style-props-value-px.html)):
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var divStyle = {
|
||||
color: 'white',
|
||||
backgroundImage: 'url(' + imgUrl + ')',
|
||||
WebkitTransition: 'all' // note the capital 'W' here
|
||||
};
|
||||
|
||||
React.renderComponent(<div style={divStyle}>Hello World!</div>, mountNode);
|
||||
```
|
||||
|
||||
Style keys are camelCased in order to be consistent with accessing the properties on DOM nodes from JS (e.g. `node.style.backgroundImage`). Vendor prefixes should begin with a capital letter. This is why `WebkitTransition` has an uppercase "W".
|
||||
42
docs/tips/03-if-else-in-JSX.md
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
id: if-else-in-JSX
|
||||
title: If-Else in JSX
|
||||
layout: tips
|
||||
permalink: if-else-in-JSX.html
|
||||
prev: inline-styles.html
|
||||
next: self-closing-tag.html
|
||||
---
|
||||
|
||||
`if-else` statements don't work inside JSX. This is because JSX is just syntactic sugar for function calls and object construction. Take this basic example:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
// This JSX:
|
||||
React.renderComponent(<div id="msg">Hello World!</div>, mountNode);
|
||||
|
||||
// Is transformed to this JS:
|
||||
React.renderComponent(React.DOM.div({id:"msg"}, "Hello World!"), mountNode);
|
||||
```
|
||||
|
||||
This means that `if` statements don't fit in. Take this example:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
// This JSX:
|
||||
<div id={if (condition) { 'msg' }}>Hello World!</div>
|
||||
|
||||
// Is transformed to this JS:
|
||||
React.DOM.div({id: if (condition) { 'msg' }}, "Hello World!");
|
||||
```
|
||||
|
||||
That's not valid JS. You probably want to make use of a ternary expression:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
React.renderComponent(<div id={condition ? 'msg' : ''}>Hello World!</div>, mountNode);
|
||||
```
|
||||
|
||||
Try using it today with the [JSX compiler](/react/jsx-compiler.html).
|
||||
14
docs/tips/04-self-closing-tag.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
id: self-closing-tag
|
||||
title: Self-Closing Tag
|
||||
layout: tips
|
||||
permalink: self-closing-tag.html
|
||||
prev: if-else-in-JSX.html
|
||||
next: maximum-number-of-jsx-root-nodes.html
|
||||
---
|
||||
|
||||
In JSX, `<MyComponent />` alone is valid while `<MyComponent>` isn't. All tags must be closed, either with the self-closing format or with a corresponding closing tag (`</MyComponent>`).
|
||||
|
||||
> Note:
|
||||
>
|
||||
> Every React component can be self-closing: `<div />`. `<div></div>` is also an equivalent.
|
||||
12
docs/tips/05-maximum-number-of-jsx-root-nodes.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
id: maximum-number-of-jsx-root-nodes
|
||||
title: Maximum Number of JSX Root Nodes
|
||||
layout: tips
|
||||
permalink: maximum-number-of-jsx-root-nodes.html
|
||||
prev: self-closing-tag.html
|
||||
next: style-props-value-px.html
|
||||
---
|
||||
|
||||
Currently, in a component's `render`, you can only return one node; if you have, say, a list of `div`s to return, you must wrap your components within a `div`, `span` or any other component.
|
||||
|
||||
Don't forget that JSX compiles into regular js; returning two functions doesn't really make syntactic sense. Likewise, don't put more than one child in a ternary.
|
||||
29
docs/tips/06-style-props-value-px.md
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
id: style-props-value-px
|
||||
title: Shorthand for Specifying Pixel Values in style props
|
||||
layout: tips
|
||||
permalink: style-props-value-px.html
|
||||
prev: maximum-number-of-jsx-root-nodes.html
|
||||
next: children-props-type.html
|
||||
---
|
||||
|
||||
When specifying a pixel value for your inline `style` prop, React automatically appends the string "px" for you after your number value, so this works:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var divStyle = {height: 10}; // rendered as "height:10px"
|
||||
React.renderComponent(<div style={divStyle}>Hello World!</div>, mountNode);
|
||||
```
|
||||
|
||||
See [Inline Styles](/react/tips/inline-styles.html) for more info.
|
||||
|
||||
Sometimes you _do_ want to keep the CSS properties unitless. Here's a list of properties that won't get the automatic "px" suffix:
|
||||
|
||||
- `fillOpacity`
|
||||
- `fontWeight`
|
||||
- `lineHeight`
|
||||
- `opacity`
|
||||
- `orphans`
|
||||
- `zIndex`
|
||||
- `zoom`
|
||||
49
docs/tips/07-children-props-type.md
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
id: children-props-type
|
||||
title: Type of the Children props
|
||||
layout: tips
|
||||
permalink: children-props-type.html
|
||||
prev: style-props-value-px.html
|
||||
next: controlled-input-null-value.html
|
||||
---
|
||||
|
||||
Usually, a component's children (`this.props.children`) is an array of components:
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var GenericWrapper = React.createClass({
|
||||
componentDidMount: function() {
|
||||
console.log(Array.isArray(this.props.children)); // => true
|
||||
},
|
||||
render: function() {
|
||||
return <div />;
|
||||
}
|
||||
});
|
||||
|
||||
React.renderComponent(
|
||||
<GenericWrapper><span/><span/><span/></GenericWrapper>,
|
||||
mountNode
|
||||
);
|
||||
```
|
||||
|
||||
However, when there is only a single child, `this.props.children` will be the single child component itself _without the array wrapper_. This saves an array allocation.
|
||||
|
||||
```js
|
||||
/** @jsx React.DOM */
|
||||
|
||||
var GenericWrapper = React.createClass({
|
||||
componentDidMount: function() {
|
||||
console.log(Array.isArray(this.props.children)); // => false
|
||||
|
||||
// warning: yields 5 for length of the string 'hello', not 1 for the
|
||||
// length of the non-existant array wrapper!
|
||||
console.log(this.props.children.length);
|
||||
},
|
||||
render: function() {
|
||||
return <div />;
|
||||
}
|
||||
});
|
||||
|
||||
React.renderComponent(<GenericWrapper>hello</GenericWrapper>, mountNode);
|
||||
```
|
||||