Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7b40b74
Translate content/docs/state-and-lifecycle.md
sorousht Mar 6, 2019
e9274f7
Apply some fixes in page "State and Lifecycle" page
sorousht Mar 7, 2019
dab9aa7
Merge pull request #32 from sorousht/state-lifecycle
sorousht Mar 8, 2019
acb2fd4
Update render-props.md (#1776)
lsdsjy Mar 9, 2019
d6d30b6
Rename App class component to Counter (#1739)
mmmurray Mar 9, 2019
c0f4b34
Fix small typo in blog post (#1803)
Luanf Mar 11, 2019
40dc7c1
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 11, 2019
439584a
Update languages.yml (#1808)
tesseralis Mar 11, 2019
b181347
Merge pull request #34 from reactjs/fa
sorousht Mar 12, 2019
d827d59
Update languages.yml (#1820)
tesseralis Mar 13, 2019
2cd4d0c
Add more info to FAQ about deps (#1815)
gaearon Mar 13, 2019
335a5a6
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 13, 2019
83faa76
Add React Alicante 2019 (#1819)
VictoriaQ Mar 13, 2019
110a318
Link to a data fetching demo
gaearon Mar 13, 2019
474de38
Use another example
gaearon Mar 13, 2019
877b189
Fix wording
gaearon Mar 13, 2019
352c3ff
Fix example
gaearon Mar 13, 2019
3e489fc
Fixing incorrect value for eslint rule (#1824)
manuelbieh Mar 14, 2019
40bbbd5
Updating useMemo docs (#1796)
DimitarNestorov Mar 14, 2019
1fe2e0a
Fix overflowing headers on small screens (#1830)
nelsonreitz Mar 15, 2019
19aecab
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 15, 2019
877431a
Fix previous article on hooks-effect.md (#1802)
arthurdenner Mar 17, 2019
50c1afe
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 18, 2019
905a113
Add React Rally 2019 (#1840)
BrianMitchL Mar 18, 2019
806da34
Add a DOM measurement recipe to Hooks FAQ (#1843)
gaearon Mar 19, 2019
ac4aa65
Add more explanations to Hooks API page (#1845)
gaearon Mar 19, 2019
b1bc193
Document useContext bailout strategy (#1848)
gaearon Mar 19, 2019
90c45d7
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 20, 2019
31b67da
Add .vscode directory to .gitignore
amiratak88 Mar 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.idea
node_modules
public
yarn-error.log
yarn-error.log
.vscode
2 changes: 1 addition & 1 deletion content/blog/2019-02-23-is-react-translated-yet.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ We started of with an initial trial period of three languages: Spanish, Japanese

After the trial period, we were ready to accept more languages. I created [a script](https://github.com/reactjs/reactjs.org-translation/blob/master/scripts/create.js) to automate the creation of the new language repo, and a site, [Is React Translated Yet?](https://isreacttranslatedyet.com), to track progress on the different translations. We started *10* new translations on our first day alone!

Because of the automation, the rest of the maintance went mostly smoothly. We eventually created a [Slack channel](https://rt-slack-invite.herokuapp.com) to make it easier for translators to share information, and I released a guide solidifying the [responsibilities of maintainers](https://github.com/reactjs/reactjs.org-translation/blob/master/maintainer-guide.md). Allowing translators to talk with each other was a great boon -- for example, the Arabic, Persian, and Hebrew translations were able to talk to each other in order to get [right-to-left text](https://en.wikipedia.org/wiki/Right-to-left) working!
Because of the automation, the rest of the maintenance went mostly smoothly. We eventually created a [Slack channel](https://rt-slack-invite.herokuapp.com) to make it easier for translators to share information, and I released a guide solidifying the [responsibilities of maintainers](https://github.com/reactjs/reactjs.org-translation/blob/master/maintainer-guide.md). Allowing translators to talk with each other was a great boon -- for example, the Arabic, Persian, and Hebrew translations were able to talk to each other in order to get [right-to-left text](https://en.wikipedia.org/wiki/Right-to-left) working!

## The Bot {#the-bot}

Expand Down
10 changes: 10 additions & 0 deletions content/community/conferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ July 15-21, 2019. New York City, USA

[Website](https://reactweek.nyc) - [Twitter](https://twitter.com/ReactWeek)

### React Rally 2019
August 22-23, 2019. Salt Lake City, USA.

[Website](https://www.reactrally.com/) - [Twitter](https://twitter.com/ReactRally) - [Instagram](https://www.instagram.com/reactrally/)

### ComponentsConf 2019 {#componentsconf-2019}
September 6, 2019 in Melbourne, Australia
[Website](https://www.componentsconf.com.au/) - [Twitter](https://twitter.com/componentsconf)
Expand All @@ -76,6 +81,11 @@ September 26-28, 2019 in Goa, India

[Website](https://www.reactindia.io/) - [Twitter](https://twitter.com/react_india) - [Facebook](https://www.facebook.com/ReactJSIndia)

### React Alicante 2019 {#react-alicante-2019}
September 26-28, 2019 in Alicante, Spain

[Website](http://reactalicante.es/) - [Twitter](https://twitter.com/reactalicante) - [Facebook](https://www.facebook.com/ReactAlicante)

## Past Conferences {#past-conferences}

### React.js Conf 2015 {#reactjs-conf-2015}
Expand Down
2 changes: 1 addition & 1 deletion content/docs/addons-test-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ To prepare a component for assertions, wrap the code rendering it and performing
For example, let's say we have this `Counter` component:

```js
class App extends React.Component {
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {count: 0};
Expand Down
24 changes: 12 additions & 12 deletions content/docs/hooks-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import React, { useState, useEffect } from 'react';
function FriendStatus(props) {
const [isOnline, setIsOnline] = useState(null);

function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
Expand All @@ -44,11 +44,11 @@ import React, { useState, useEffect } from 'react';
function FriendListItem(props) {
const [isOnline, setIsOnline] = useState(null);

function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
Expand Down Expand Up @@ -79,11 +79,11 @@ import React, { useState, useEffect } from 'react';
function useFriendStatus(friendID) {
const [isOnline, setIsOnline] = useState(null);

function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(friendID, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(friendID, handleStatusChange);
Expand Down
39 changes: 26 additions & 13 deletions content/docs/hooks-effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: hooks-state
title: Using the Effect Hook
permalink: docs/hooks-effect.html
next: hooks-rules.html
prev: hooks-intro.html
prev: hooks-state.html
---

*Hooks* are a new addition in React 16.8. They let you use state and other React features without writing a class.
Expand Down Expand Up @@ -198,17 +198,17 @@ Let's see how we could write this component with Hooks.

You might be thinking that we'd need a separate effect to perform the cleanup. But code for adding and removing a subscription is so tightly related that `useEffect` is designed to keep it together. If your effect returns a function, React will run it when it is time to clean up:

```js{10-16}
```js{6-16}
import React, { useState, useEffect } from 'react';

function FriendStatus(props) {
const [isOnline, setIsOnline] = useState(null);

function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
// Specify how to clean up after this effect:
return function cleanup() {
Expand Down Expand Up @@ -237,6 +237,10 @@ We've learned that `useEffect` lets us express different kinds of side effects a

```js
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
Expand Down Expand Up @@ -316,15 +320,15 @@ function FriendStatusWithCounter(props) {

const [isOnline, setIsOnline] = useState(null);
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
};
});

function handleStatusChange(status) {
setIsOnline(status.isOnline);
}
// ...
}
```
Expand Down Expand Up @@ -394,6 +398,7 @@ Now consider the version of this component that uses Hooks:
function FriendStatus(props) {
// ...
useEffect(() => {
// ...
ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
Expand Down Expand Up @@ -449,8 +454,12 @@ When we render with `count` updated to `6`, React will compare the items in the

This also works for effects that have a cleanup phase:

```js{6}
```js{10}
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}

ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
return () => {
ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);
Expand All @@ -462,9 +471,13 @@ In the future, the second argument might get added automatically by a build-time

>Note
>
>If you use this optimization, make sure the array includes **any values from the outer scope that change over time and that are used by the effect**. Otherwise, your code will reference stale values from previous renders. We'll also discuss other optimization options in the [Hooks API reference](/docs/hooks-reference.html).
>If you use this optimization, make sure the array includes **all values from the component scope (such as props and state) that change over time and that are used by the effect**. Otherwise, your code will reference stale values from previous renders. Learn more about [how to deal with functions](/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies) and [what to do when the array changes too often](/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often).
>
>If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array (`[]`) as a second argument. This tells React that your effect doesn't depend on *any* values from props or state, so it never needs to re-run. This isn't handled as a special case -- it follows directly from how the inputs array always works.
>
>If you pass an empty array (`[]`), the props and state inside the effect will always have their initial values. While passing `[]` as the second argument is closer to the familiar `componentDidMount` and `componentWillUnmount` mental model, there are usually [better](/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies) [solutions](/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often) to avoid re-running effects too often. Also, don't forget that React defers running `useEffect` until after the browser has painted, so doing extra work is less of a problem.
>
>If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array (`[]`) as a second argument. This tells React that your effect doesn't depend on *any* values from props or state, so it never needs to re-run. This isn't handled as a special case -- it follows directly from how the inputs array always works. While passing `[]` is closer to the familiar `componentDidMount` and `componentWillUnmount` mental model, we suggest not making it a habit because it often leads to bugs, [as discussed above](#explanation-why-effects-run-on-each-update). Don't forget that React defers running `useEffect` until after the browser has painted, so doing extra work is less of a problem.
>We recommend using the [`exhaustive-deps`](https://github.com/facebook/react/issues/14920) rule as part of our [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks#installation) package. It warns when dependencies are specified incorrectly and suggests a fix.

## Next Steps {#next-steps}

Expand Down
Loading