From 905a1134c07ea24aa4e4e4351371cf77b027280a Mon Sep 17 00:00:00 2001 From: Brian Mitchell Date: Mon, 18 Mar 2019 12:24:24 -0500 Subject: [PATCH 1/8] Add React Rally 2019 (#1840) --- content/community/conferences.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/community/conferences.md b/content/community/conferences.md index e138b119a..ea8613c78 100644 --- a/content/community/conferences.md +++ b/content/community/conferences.md @@ -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) From 4508b324c30b27d277cb32eee43e827e42e9f8e6 Mon Sep 17 00:00:00 2001 From: Fagan Saidzade Date: Mon, 18 Mar 2019 21:42:26 +0400 Subject: [PATCH 2/8] Translated languages' page and list --- content/languages.yml | 80 +++++++++++++++++++++--------------------- src/pages/languages.js | 14 ++++---- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/content/languages.yml b/content/languages.yml index 5e0958260..ae9f90c3a 100644 --- a/content/languages.yml +++ b/content/languages.yml @@ -3,162 +3,162 @@ # 1: Partially complete (50-99%) # 2: Complete (100%) -- name: English +- name: İngiliscə translated_name: English code: en status: 2 -- name: Arabic +- name: Ərəbcə translated_name: العربية code: ar status: 0 -- name: Azerbaijani +- name: Azərbaycanca translated_name: Azərbaycanca code: az status: 0 -- name: Bulgarian +- name: Bolqarca translated_name: Български code: bg status: 0 -- name: Bengali +- name: Benqalca translated_name: বাংলা code: bn status: 0 -- name: German +- name: Almanca translated_name: Deutsch code: de status: 1 -- name: Greek +- name: Yunanca translated_name: Ελληνικά code: el status: 0 -- name: Spanish +- name: İspanca translated_name: Español code: es status: 2 -- name: Persian +- name: Farsca translated_name: فارسی code: fa status: 0 -- name: French +- name: Fransızca translated_name: Français code: fr status: 2 -- name: Gujarati +- name: Qucarat dilində translated_name: ગુજરાતી code: gu status: 0 -- name: Hebrew +- name: Yəhudicə translated_name: עברית code: he status: 1 -- name: Hindi +- name: Hind dilində translated_name: हिन्दी code: hi status: 0 -- name: Armenian +- name: Ermənicə translated_name: Հայերեն code: hy status: 0 -- name: Indonesian +- name: İndoneziya dilində translated_name: Bahasa Indonesia code: id status: 0 -- name: Italian +- name: İtalyanca translated_name: Italiano code: it status: 0 -- name: Japanese +- name: Yaponca translated_name: 日本語 code: ja status: 2 -- name: Central Khmer +- name: Mərkəzi Kxmer dilində translated_name: ភាសាខ្មែរ code: km status: 0 -- name: Korean +- name: Koreya dilində translated_name: 한국어 code: ko status: 1 -- name: Kurdish +- name: Kürdcə translated_name: کوردی‎ code: ku status: 0 -- name: Lithuanian +- name: Litva dilində translated_name: Lietuvių kalba code: lt status: 0 -- name: Malayalam +- name: Malayalam dilində translated_name: മലയാളം code: ml status: 0 -- name: Nepali +- name: Nepalca translated_name: नेपाली code: ne status: 0 -- name: Dutch +- name: Hollandca translated_name: Nederlands code: nl status: 0 -- name: Polish +- name: Polyakca translated_name: Polski code: pl status: 1 -- name: Portuguese (Brazil) +- name: Portuqalca (Braziliya) translated_name: Português do Brasil code: pt-br status: 2 -- name: Portuguese (Portugal) +- name: Portuqalca (Portuqaliya) translated_name: Português europeu code: pt-pt status: 0 -- name: Romanian +- name: Rumınca translated_name: Română code: ro status: 0 -- name: Russian +- name: Rusca translated_name: Русский code: ru status: 2 -- name: Sinhala +- name: Sinhal dilində translated_name: සිංහල code: si status: 0 -- name: Swedish +- name: İsveç dilində translated_name: Svenska code: sv -- name: Tamil +- name: Tamil dilində translated_name: தமிழ் code: ta status: 0 -- name: Telugu +- name: Teluqu dilində translated_name: తెలుగు code: te status: 0 -- name: Turkish +- name: Türkcə translated_name: Türkçe code: tr status: 1 -- name: Ukrainian +- name: Ukraynca translated_name: Українська code: uk status: 1 -- name: Urdu +- name: Urdu dilində translated_name: اردو code: ur status: 0 -- name: Uzbek +- name: Özbəkcə translated_name: Oʻzbekcha code: uz status: 0 -- name: Vietnamese +- name: Vyetnamca translated_name: Tiếng Việt code: vi status: 0 -- name: Simplified Chinese +- name: Sadələşdirilmiş Çin dilində translated_name: 简体中文 code: zh-hans status: 1 -- name: Traditional Chinese +- name: Ənənəvi Çin dilində translated_name: 繁體中文 code: zh-hant status: 0 diff --git a/src/pages/languages.js b/src/pages/languages.js index 61f063125..add95380d 100644 --- a/src/pages/languages.js +++ b/src/pages/languages.js @@ -46,29 +46,29 @@ const Languages = ({location}: Props) => (
-
Languages
+
Dillər

- The React documentation is available in the following languages: + React-ın sənədləri aşağıdakı dillərdə mövcuddur:

-

In Progress

+

Üzərində iş gedir

-

Needs Contributors

+

İştirakçıya ehtiyac var

- Don't see your language above?{' '} + Öz dilini yuxarıda görmürsən?{' '} - Let us know + Bizə bildir .

@@ -149,7 +149,7 @@ const Language = ({code, name, status, translatedName}) => { href={`https://github.com/reactjs/${prefix}reactjs.org/`} target="_blank" rel="noopener"> - Contribute + İştirak et
From 806da34988106c2a92c9784edc2bc0e91333ca4a Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 19 Mar 2019 15:28:18 +0000 Subject: [PATCH 3/8] Add a DOM measurement recipe to Hooks FAQ (#1843) * Add a DOM measurement recipe to Hooks FAQ * Update content/docs/hooks-faq.md Co-Authored-By: gaearon * Update content/docs/hooks-faq.md Co-Authored-By: gaearon --- content/docs/hooks-faq.md | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/content/docs/hooks-faq.md b/content/docs/hooks-faq.md index 9016fa7f4..1e68b379c 100644 --- a/content/docs/hooks-faq.md +++ b/content/docs/hooks-faq.md @@ -41,6 +41,7 @@ This page answers some of the frequently asked questions about [Hooks](/docs/hoo * [How do I implement getDerivedStateFromProps?](#how-do-i-implement-getderivedstatefromprops) * [Is there something like forceUpdate?](#is-there-something-like-forceupdate) * [Can I make a ref to a function component?](#can-i-make-a-ref-to-a-function-component) + * [How can I measure a DOM node?](#how-can-i-measure-a-dom-node) * [What does const [thing, setThing] = useState() mean?](#what-does-const-thing-setthing--usestate-mean) * **[Performance Optimizations](#performance-optimizations)** * [Can I skip an effect on updates?](#can-i-skip-an-effect-on-updates) @@ -451,6 +452,60 @@ Try to avoid this pattern if possible. While you shouldn't need this often, you may expose some imperative methods to a parent component with the [`useImperativeHandle`](/docs/hooks-reference.html#useimperativehandle) Hook. +### How can I measure a DOM node? {#how-can-i-measure-a-dom-node} + +In order to measure the position or size of a DOM node, you can use a [callback ref](/docs/refs-and-the-dom.html#callback-refs). React will call that callback whenever the ref gets attached to a different node. Here is a [small demo](https://codesandbox.io/s/l7m0v5x4v9): + +```js{4-8,12} +function MeasureExample() { + const [height, setHeight] = useState(0); + + const measuredRef = useCallback(node => { + if (node !== null) { + setHeight(node.getBoundingClientRect().height); + } + }, []); + + return ( + <> +

Hello, world

+

The above header is {Math.round(height)}px tall

+ + ); +} +``` + +We didn't choose `useRef` in this example because an object ref doesn't notify us about *changes* to the current ref value. Using a callback ref ensures that [even if a child component displays the measured node later](https://codesandbox.io/s/818zzk8m78) (e.g. in response to a click), we still get notified about it in the parent component and can update the measurements. + +Note that we pass `[]` as a dependency array to `useCallback`. This ensures that our ref callback doesn't change between the re-renders, and so React won't call it unnecessarily. + +If you want, you can [extract this logic](https://codesandbox.io/s/m5o42082xy) into a reusable Hook: + +```js{2} +function MeasureExample() { + const [rect, ref] = useClientRect(); + return ( + <> +

Hello, world

+ {rect !== null && +

The above header is {Math.round(rect.height)}px tall

+ } + + ); +} + +function useClientRect() { + const [rect, setRect] = useState(null); + const ref = useCallback(node => { + if (node !== null) { + setRect(node.getBoundingClientRect()); + } + }, []); + return [rect, ref]; +} +``` + + ### What does `const [thing, setThing] = useState()` mean? {#what-does-const-thing-setthing--usestate-mean} If you're not familiar with this syntax, check out the [explanation](/docs/hooks-state.html#tip-what-do-square-brackets-mean) in the State Hook documentation. From ac4aa6546e413bc6bdc6d8191081b739fbc6fb27 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 19 Mar 2019 17:12:44 +0000 Subject: [PATCH 4/8] Add more explanations to Hooks API page (#1845) * Add more explanations to API page * static * add info about useLayoutEffect * Update content/docs/hooks-reference.md Co-Authored-By: gaearon * nits * nit --- content/docs/hooks-faq.md | 4 ++-- content/docs/hooks-reference.md | 39 ++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/content/docs/hooks-faq.md b/content/docs/hooks-faq.md index 1e68b379c..7d2953293 100644 --- a/content/docs/hooks-faq.md +++ b/content/docs/hooks-faq.md @@ -908,7 +908,7 @@ function Form() { const [text, updateText] = useState(''); const textRef = useRef(); - useLayoutEffect(() => { + useEffect(() => { textRef.current = text; // Write it to the ref }); @@ -949,7 +949,7 @@ function useEventCallback(fn, dependencies) { throw new Error('Cannot call an event handler while rendering.'); }); - useLayoutEffect(() => { + useEffect(() => { ref.current = fn; }, [fn, ...dependencies]); diff --git a/content/docs/hooks-reference.md b/content/docs/hooks-reference.md index 4daf0f191..f2cc087d4 100644 --- a/content/docs/hooks-reference.md +++ b/content/docs/hooks-reference.md @@ -97,6 +97,8 @@ const [state, setState] = useState(() => { If you update a State Hook to the same value as the current state, React will bail out without rendering the children or firing effects. (React uses the [`Object.is` comparison algorithm](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Description).) +Note that React may still need to render that specific component again before bailing out. That shouldn't be a concern because React won't unnecessarily go "deeper" into the tree. If you're doing expensive calculations while rendering, you can optimize them with `useMemo`. + ### `useEffect` {#useeffect} ```js @@ -173,12 +175,24 @@ The array of dependencies is not passed as arguments to the effect function. Con ### `useContext` {#usecontext} ```js -const context = useContext(Context); +const value = useContext(MyContext); ``` -Accepts a context object (the value returned from `React.createContext`) and returns the current context value, as given by the nearest context provider for the given context. +Accepts a context object (the value returned from `React.createContext`) and returns the current context value for that context. The current context value is determined by the `value` prop of the nearest `` above the calling component in the tree. + +When the nearest `` above the component updates, this Hook will trigger a rerender with the latest context `value` passed to that `MyContext` provider. -When the provider updates, this Hook will trigger a rerender with the latest context value. +Don't forget that the argument to `useContext` must be the *context object itself*: + + * **Correct:** `useContext(MyContext)` + * **Incorrect:** `useContext(MyContext.Consumer)` + * **Incorrect:** `useContext(MyContext.Provider)` + +>Tip +> +>If you're familiar with the context API before Hooks, `useContext(MyContext)` is equivalent to `static contextType = MyContext` in a class, or to ``. +> +>`useContext(MyContext)` only lets you *read* the context and subscribe to its changes. You still need a `` above in the tree to *provide* the value for this context. ## Additional Hooks {#additional-hooks} @@ -285,6 +299,8 @@ function Counter({initialCount}) { If you return the same value from a Reducer Hook as the current state, React will bail out without rendering the children or firing effects. (React uses the [`Object.is` comparison algorithm](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Description).) +Note that React may still need to render that specific component again before bailing out. That shouldn't be a concern because React won't unnecessarily go "deeper" into the tree. If you're doing expensive calculations while rendering, you can optimize them with `useMemo`. + ### `useCallback` {#usecallback} ```js @@ -356,7 +372,16 @@ function TextInputWithFocusButton() { } ``` -Note that `useRef()` is useful for more than the `ref` attribute. It's [handy for keeping any mutable value around](/docs/hooks-faq.html#is-there-something-like-instance-variables) similar to how you'd use instance fields in classes. +Essentially, `useRef` is like a "box" that can hold a mutable value in its `.current` property. + +You might be familiar with refs primarily as a way to [access the DOM](/docs/refs-and-the-dom.html). If you pass a ref object to React with `
`, React will set its `.current` property to the corresponding DOM node whenever that node changes. + +However, `useRef()` is useful for more than the `ref` attribute. It's [handy for keeping any mutable value around](/docs/hooks-faq.html#is-there-something-like-instance-variables) similar to how you'd use instance fields in classes. + +This works because `useRef()` creates a plain JavaScript object. The only difference between `useRef()` and creating a `{current: ...}` object yourself is that `useRef` will give you the same ref object on every render. + +Keep in mind that `useRef` *doesn't* notify you when its content changes. Mutating the `.current` property doesn't cause a re-render. If you want to run some code when React attaches or detaches a ref to a DOM node, you may want to use a [callback ref](/docs/hooks-faq.html#how-can-i-measure-a-dom-node) instead. + ### `useImperativeHandle` {#useimperativehandle} @@ -389,7 +414,11 @@ Prefer the standard `useEffect` when possible to avoid blocking visual updates. > Tip > -> If you're migrating code from a class component, `useLayoutEffect` fires in the same phase as `componentDidMount` and `componentDidUpdate`, so if you're unsure of which effect Hook to use, it's probably the least risky. +> If you're migrating code from a class component, note `useLayoutEffect` fires in the same phase as `componentDidMount` and `componentDidUpdate`. However, **we recommend starting with `useEffect` first** and only trying `useLayoutEffect` if that causes a problem. +> +>If you use server rendering, keep in mind that *neither* `useLayoutEffect` nor `useEffect` can run until the JavaScript is downloaded. This is why React warns when a server-rendered component contains `useLayoutEffect`. To fix this, either move that logic to `useEffect` (if it isn't necessary for the first render), or delay showing that component until after the client renders (if the HTML looks broken until `useLayoutEffect` runs). +> +>To exclude a component that needs layout effects from the server-rendered HTML, render it conditionally with `showChild && ` and defer showing it with `useEffect(() => { setShowChild(true); }, [])`. This way, the UI doesn't appear broken before hydration. ### `useDebugValue` {#usedebugvalue} From b1bc193dbad464f7c659b10f3f57e37e265a063e Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 19 Mar 2019 22:09:21 +0000 Subject: [PATCH 5/8] Document useContext bailout strategy (#1848) --- content/docs/hooks-reference.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/docs/hooks-reference.md b/content/docs/hooks-reference.md index f2cc087d4..98c2e14c0 100644 --- a/content/docs/hooks-reference.md +++ b/content/docs/hooks-reference.md @@ -188,6 +188,8 @@ Don't forget that the argument to `useContext` must be the *context object itsel * **Incorrect:** `useContext(MyContext.Consumer)` * **Incorrect:** `useContext(MyContext.Provider)` +A component calling `useContext` will always re-render when the context value changes. If re-rendering the component is expensive, you can [optimize it by using memoization](https://github.com/facebook/react/issues/15156#issuecomment-474590693). + >Tip > >If you're familiar with the context API before Hooks, `useContext(MyContext)` is equivalent to `static contextType = MyContext` in a class, or to ``. From 5c944193cb869c2f13c674f6e90d78f09215792d Mon Sep 17 00:00:00 2001 From: saidfagan Date: Wed, 20 Mar 2019 20:37:05 +0400 Subject: [PATCH 6/8] Fixed suffixes according to glossary --- content/docs/hello-world.md | 4 ++-- src/pages/languages.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/docs/hello-world.md b/content/docs/hello-world.md index 6d7312b3f..2bbe0d149 100644 --- a/content/docs/hello-world.md +++ b/content/docs/hello-world.md @@ -24,13 +24,13 @@ Online dəyişmək üçün yuxarıda qeyd olunan linkə keçid edə bilərsiniz. ## Təlimatı necə oxumaq lazımdır {#how-to-read-this-guide} -Təlimatda, React-ın əsas fundamental blokları haqqında bəhs edəcəyik: element və komponent. Onları yaxşı mənimsədikdən sonra, kiçik təkrar istifadə oluna bilən bloklardan kompleks tətbiqlər yarada biləcəksiniz. +Təlimatda, React-in əsas fundamental blokları haqqında bəhs edəcəyik: element və komponent. Onları yaxşı mənimsədikdən sonra, kiçik təkrar istifadə oluna bilən bloklardan kompleks tətbiqlər yarada biləcəksiniz. >Məsləhət > >Təlimat **addım-addım öyrənməyi** tərcih edən insanlar üçün nəzərdə tutulub. Əgər siz praktika edərək öyrənməyi tərcih edirsinizsə, [praktiki təlimat](/tutorial/tutorial.html) nəzər yetirin. Bu təlimatlar bir-birini tamamlayır. -Bu, React-ın əsas konseptlərini addım-addım öyrən təlimatının birinci hissədir. Sağdakı siyahıda təlimatın bütün hissələri ilə tanış ola bilərsiniz. Siz bunu mobildən oxuyursunuzsa sağ yuxarıda olan düymədən istifadə edərək siyahını görə bilərsiniz. +Bu, React-in əsas konseptlərini addım-addım öyrən təlimatının birinci hissədir. Sağdakı siyahıda təlimatın bütün hissələri ilə tanış ola bilərsiniz. Siz bunu mobildən oxuyursunuzsa sağ yuxarıda olan düymədən istifadə edərək siyahını görə bilərsiniz. Təlimatda hər bir hissə öncə olan hissədən öyrəndiyimiz biliklərə əsaslanır. **Siyahıdan “Əsas Konseptlər” bölməsini seçib oxuyaraq React haqqında daha çox öyrənə bilərsiniz.** Misal üçün [“JSX-ə giriş”](/docs/introducing-jsx.html) bundan sonrakı hissədir. diff --git a/src/pages/languages.js b/src/pages/languages.js index add95380d..eaff7cf2d 100644 --- a/src/pages/languages.js +++ b/src/pages/languages.js @@ -51,7 +51,7 @@ const Languages = ({location}: Props) => (

- React-ın sənədləri aşağıdakı dillərdə mövcuddur: + React-in sənədləri aşağıdakı dillərdə mövcuddur:

From 1f2dbb7a4f531d1c9d70ae69e025eac992b37c6a Mon Sep 17 00:00:00 2001 From: Nat Alison Date: Wed, 20 Mar 2019 13:03:43 -0700 Subject: [PATCH 7/8] Update languages for Simplified Chinese completion (#1854) * Update languages for Simplified Chinese completion * Update languages.yml --- content/languages.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/content/languages.yml b/content/languages.yml index 5e0958260..524c41c73 100644 --- a/content/languages.yml +++ b/content/languages.yml @@ -66,11 +66,15 @@ - name: Italian translated_name: Italiano code: it - status: 0 + status: 1 - name: Japanese translated_name: 日本語 code: ja status: 2 +- name: Georgian + translated_name: ქართული + code: ka + status: 0 - name: Central Khmer translated_name: ភាសាខ្មែរ code: km @@ -126,6 +130,7 @@ - name: Swedish translated_name: Svenska code: sv + status: 0 - name: Tamil translated_name: தமிழ் code: ta @@ -134,6 +139,10 @@ translated_name: తెలుగు code: te status: 0 +- name: Thai + translated_name: ไทย + code: th + status: 0 - name: Turkish translated_name: Türkçe code: tr @@ -157,7 +166,7 @@ - name: Simplified Chinese translated_name: 简体中文 code: zh-hans - status: 1 + status: 2 - name: Traditional Chinese translated_name: 繁體中文 code: zh-hant From 0516ab3de81299f0eccd6fe62fd5ee9206c74f8d Mon Sep 17 00:00:00 2001 From: Gasim Gasimzada Date: Fri, 22 Mar 2019 22:57:27 +0400 Subject: [PATCH 8/8] Update languages.yml --- content/languages.yml | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/content/languages.yml b/content/languages.yml index 035bc26cc..509726e4d 100644 --- a/content/languages.yml +++ b/content/languages.yml @@ -66,25 +66,16 @@ - name: İtalyanca translated_name: Italiano code: it -<<<<<<< HEAD - status: 0 -- name: Yaponca - translated_name: 日本語 - code: ja - status: 2 -- name: Mərkəzi Kxmer dilində -======= status: 1 -- name: Japanese +- name: Yaponca translated_name: 日本語 code: ja status: 2 -- name: Georgian +- name: Gürcü dilində translated_name: ქართული code: ka status: 0 -- name: Central Khmer ->>>>>>> 1f2dbb7a4f531d1c9d70ae69e025eac992b37c6a +- name: Mərkəzi Kxmer dilində translated_name: ភាសាខ្មែរ code: km status: 0 @@ -139,12 +130,8 @@ - name: İsveç dilində translated_name: Svenska code: sv -<<<<<<< HEAD -- name: Tamil dilində -======= status: 0 -- name: Tamil ->>>>>>> 1f2dbb7a4f531d1c9d70ae69e025eac992b37c6a +- name: Tamil dilində translated_name: தமிழ் code: ta status: 0 @@ -152,15 +139,11 @@ translated_name: తెలుగు code: te status: 0 -<<<<<<< HEAD -- name: Türkcə -======= -- name: Thai +- name: Tay dilində translated_name: ไทย code: th status: 0 -- name: Turkish ->>>>>>> 1f2dbb7a4f531d1c9d70ae69e025eac992b37c6a +- name: Türkcə translated_name: Türkçe code: tr status: 1 @@ -183,13 +166,8 @@ - name: Sadələşdirilmiş Çin dilində translated_name: 简体中文 code: zh-hans -<<<<<<< HEAD - status: 1 -- name: Ənənəvi Çin dilində -======= status: 2 -- name: Traditional Chinese ->>>>>>> 1f2dbb7a4f531d1c9d70ae69e025eac992b37c6a +- name: Ənənəvi Çin dilində translated_name: 繁體中文 code: zh-hant status: 0