Skip to content

Commit 81afcfb

Browse files
authored
Functional -> function (#863)
1 parent f49ae19 commit 81afcfb

19 files changed

+41
-41
lines changed

content/blog/2015-10-07-react-v0.14.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ If you can’t use `npm` yet, we provide pre-built browser builds for your conve
104104

105105
With this change, we’re deprecating `.getDOMNode()` and replacing it with `ReactDOM.findDOMNode` (see below). If your components are currently using `.getDOMNode()`, they will continue to work with a warning until 0.15.
106106

107-
- #### Stateless functional components
107+
- #### Stateless function components
108108

109109
In idiomatic React code, most of the components you write will be stateless, simply composing other components. We’re introducing a new, simpler syntax for these components where you can take `props` as an argument and return the element you want to render:
110110

111111
```js
112-
// A functional component using an ES2015 (ES6) arrow function:
112+
// A function component using an ES2015 (ES6) arrow function:
113113
var Aquarium = (props) => {
114114
var fish = getFish(props.species);
115115
return <Tank>{fish}</Tank>;
@@ -125,7 +125,7 @@ If you can’t use `npm` yet, we provide pre-built browser builds for your conve
125125
// Then use: <Aquarium species="rainbowfish" />
126126
```
127127
128-
These components behave just like a React class with only a `render` method defined. Since no component instance is created for a functional component, any `ref` added to one will evaluate to `null`. Functional components do not have lifecycle methods, but you can set `.propTypes` and `.defaultProps` as properties on the function.
128+
These components behave just like a React class with only a `render` method defined. Since no component instance is created for a function component, any `ref` added to one will evaluate to `null`. Function components do not have lifecycle methods, but you can set `.propTypes` and `.defaultProps` as properties on the function.
129129
130130
This pattern is designed to encourage the creation of these simple components that should comprise large portions of your apps. In the future, we’ll also be able to make performance optimizations specific to these components by avoiding unnecessary checks and memory allocations.
131131

content/blog/2015-12-18-react-components-elements-and-instances.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ class Button extends React.Component {
294294
}
295295
```
296296
297-
When a component is defined as a class, it is a little bit more powerful than a functional component. It can store some local state and perform custom logic when the corresponding DOM node is created or destroyed.
297+
When a component is defined as a class, it is a little bit more powerful than a function component. It can store some local state and perform custom logic when the corresponding DOM node is created or destroyed.
298298
299-
A functional component is less powerful but is simpler, and acts like a class component with just a single `render()` method. Unless you need features available only in a class, we encourage you to use functional components instead.
299+
A function component is less powerful but is simpler, and acts like a class component with just a single `render()` method. Unless you need features available only in a class, we encourage you to use function components instead.
300300
301301
**However, whether functions or classes, fundamentally they are all components to React. They take the props as their input, and return the elements as their output.**
302302
@@ -370,7 +370,7 @@ When a component receives some props as an input, it is because a particular par
370370
371371
An *instance* is what you refer to as `this` in the component class you write. It is useful for [storing local state and reacting to the lifecycle events](/docs/component-api.html).
372372
373-
Functional components don’t have instances at all. Class components have instances, but you never need to create a component instance directly—React takes care of this.
373+
Function components don’t have instances at all. Class components have instances, but you never need to create a component instance directly—React takes care of this.
374374
375375
Finally, to create elements, use [`React.createElement()`](/docs/top-level-api.html#react.createelement), [JSX](/docs/jsx-in-depth.html), or an [element factory helper](/docs/top-level-api.html#react.createfactory). Don’t write elements as plain objects in the real code—just know that they are plain objects under the hood.
376376

content/blog/2016-04-07-react-v15.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ If you can’t use `npm` yet, we provide pre-built browser builds for your conve
7171

7272
<small>[@sophiebits](https://github.com/sophiebits) in [#5451](https://github.com/facebook/react/pull/5451)</small>
7373

74-
- #### Functional components can now return `null` too
74+
- #### Function components can now return `null` too
7575

7676
We added support for [defining stateless components as functions](/blog/2015/09/10/react-v0.14-rc1.html#stateless-function-components) in React 0.14. However, React 0.14 still allowed you to define a class component without extending `React.Component` or using `React.createClass()`, so [we couldn’t reliably tell if your component is a function or a class](https://github.com/facebook/react/issues/5355), and did not allow returning `null` from it. This issue is solved in React 15, and you can now return `null` from any component, whether it is a class or a function.
7777

content/blog/2016-07-13-mixins-considered-harmful.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function withSubscription(WrappedComponent) {
373373
});
374374
}
375375

376-
// Optional change: convert CommentList to a functional component
376+
// Optional change: convert CommentList to a function component
377377
// because it doesn't use lifecycle hooks or state.
378378
function CommentList(props) {
379379
var comments = props.comments;
@@ -467,7 +467,7 @@ Props keep component dependencies explicit, easy to replace, and enforceable wit
467467

468468
> **Note:**
469469
>
470-
> Defining components as functions is not required. There is also nothing wrong with using lifecycle hooks and state—they are first-class React features. We use functional components in this example because they are easier to read and we didn’t need those extra features, but classes would work just as fine.
470+
> Defining components as functions is not required. There is also nothing wrong with using lifecycle hooks and state—they are first-class React features. We use function components in this example because they are easier to read and we didn’t need those extra features, but classes would work just as fine.
471471
472472
### Context
473473

content/blog/2017-04-07-react-v15.5.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ You may also consider using [Flow](https://flow.org/) to statically type check y
6969

7070
When React was initially released, there was no idiomatic way to create classes in JavaScript, so we provided our own: `React.createClass`.
7171

72-
Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. **Along with functional components, JavaScript classes are now the [preferred way to create components in React](/docs/components-and-props.html#functional-and-class-components).**
72+
Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. **Along with function components, JavaScript classes are now the [preferred way to create components in React](/docs/components-and-props.html#functional-and-class-components).**
7373

7474
For your existing `createClass` components, we recommend that you migrate them to JavaScript classes. However, if you have components that rely on mixins, converting to classes may not be immediately feasible. If so, `create-react-class` is available on npm as a drop-in replacement:
7575

content/blog/2018-03-29-react-v-16-3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Version 16.3 adds a new option for managing refs that offers the convenience of
4141

4242
Generally, React components are declarative, but sometimes imperative access to the component instances and the underlying DOM nodes is necessary. This is common for use cases like managing focus, selection, or animations. React provides [refs](/docs/refs-and-the-dom.html) as a way to solve this problem. However, component encapsulation poses some challenges with refs.
4343

44-
For example, if you replace a `<button>` with a custom `<FancyButton>` component, the `ref` attribute on it will start pointing at the wrapper component instead of the DOM node (and would be `null` for functional components). While this is desirable for "application-level" components like `FeedStory` or `Comment` that need to be encapsulated, it can be annoying for "leaf" components such as `FancyButton` or `MyTextInput` that are typically used like their DOM counterparts, and might need to expose their DOM nodes.
44+
For example, if you replace a `<button>` with a custom `<FancyButton>` component, the `ref` attribute on it will start pointing at the wrapper component instead of the DOM node (and would be `null` for function components). While this is desirable for "application-level" components like `FeedStory` or `Comment` that need to be encapsulated, it can be annoying for "leaf" components such as `FancyButton` or `MyTextInput` that are typically used like their DOM counterparts, and might need to expose their DOM nodes.
4545

4646
Ref forwarding is a new opt-in feature that lets some components take a `ref` they receive, and pass it further down (in other words, "forward" it) to a child. In the example below, `FancyButton` forwards its ref to a DOM `button` that it renders:
4747

content/blog/2018-06-07-you-probably-dont-need-derived-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ This design is fundamentally flawed, but it's also an easy mistake to make. ([I'
104104

105105
### Recommendation: Fully controlled component
106106

107-
One way to avoid the problems mentioned above is to remove state from our component entirely. If the email address only exists as a prop, then we don't have to worry about conflicts with state. We could even convert `EmailInput` to a lighter-weight functional component:
107+
One way to avoid the problems mentioned above is to remove state from our component entirely. If the email address only exists as a prop, then we don't have to worry about conflicts with state. We could even convert `EmailInput` to a lighter-weight function component:
108108
```js
109109
function EmailInput(props) {
110110
return <input onChange={props.onChange} value={props.email} />;

content/docs/components-and-props.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Components let you split the UI into independent, reusable pieces, and think abo
2020

2121
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen.
2222

23-
## Functional and Class Components
23+
## Function and Class Components
2424

2525
The simplest way to define a component is to write a JavaScript function:
2626

@@ -30,7 +30,7 @@ function Welcome(props) {
3030
}
3131
```
3232

33-
This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "functional" because they are literally JavaScript functions.
33+
This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "function components" because they are literally JavaScript functions.
3434

3535
You can also use an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) to define a component:
3636

@@ -44,7 +44,7 @@ class Welcome extends React.Component {
4444

4545
The above two components are equivalent from React's point of view.
4646

47-
Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use functional components for their conciseness.
47+
Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness.
4848

4949
## Rendering a Component
5050

@@ -237,7 +237,7 @@ Extracting components might seem like grunt work at first, but having a palette
237237

238238
## Props are Read-Only
239239

240-
Whether you declare a component [as a function or a class](#functional-and-class-components), it must never modify its own props. Consider this `sum` function:
240+
Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum` function:
241241

242242
```js
243243
function sum(a, b) {

content/docs/forwarding-refs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Here is a step-by-step explanation of what happens in the above example:
3333

3434
>Note
3535
>
36-
>The second `ref` argument only exists when you define a component with `React.forwardRef` call. Regular functional or class components don't receive the `ref` argument, and ref is not available in props either.
36+
>The second `ref` argument only exists when you define a component with `React.forwardRef` call. Regular function or class components don't receive the `ref` argument, and ref is not available in props either.
3737
>
3838
>Ref forwarding is not limited to DOM components. You can forward refs to class component instances, too.
3939

content/docs/higher-order-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function logProps(InputComponent) {
190190
const EnhancedComponent = logProps(InputComponent);
191191
```
192192

193-
There are a few problems with this. One is that the input component cannot be reused separately from the enhanced component. More crucially, if you apply another HOC to `EnhancedComponent` that *also* mutates `componentWillReceiveProps`, the first HOC's functionality will be overridden! This HOC also won't work with functional components, which do not have lifecycle methods.
193+
There are a few problems with this. One is that the input component cannot be reused separately from the enhanced component. More crucially, if you apply another HOC to `EnhancedComponent` that *also* mutates `componentWillReceiveProps`, the first HOC's functionality will be overridden! This HOC also won't work with function components, which do not have lifecycle methods.
194194

195195
Mutating HOCs are a leaky abstraction—the consumer must know how they are implemented in order to avoid conflicts with other HOCs.
196196

@@ -211,7 +211,7 @@ function logProps(WrappedComponent) {
211211
}
212212
```
213213

214-
This HOC has the same functionality as the mutating version while avoiding the potential for clashes. It works equally well with class and functional components. And because it's a pure function, it's composable with other HOCs, or even with itself.
214+
This HOC has the same functionality as the mutating version while avoiding the potential for clashes. It works equally well with class and function components. And because it's a pure function, it's composable with other HOCs, or even with itself.
215215

216216
You may have noticed similarities between HOCs and a pattern called **container components**. Container components are part of a strategy of separating responsibility between high-level and low-level concerns. Containers manage things like subscriptions and state, and pass props to components that handle things like rendering UI. HOCs use containers as part of their implementation. You can think of HOCs as parameterized container component definitions.
217217

content/docs/implementation-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class DOMComponent {
376376

377377
The main difference after refactoring from `mountHost()` is that we now keep `this.node` and `this.renderedChildren` associated with the internal DOM component instance. We will also use them for applying non-destructive updates in the future.
378378

379-
As a result, each internal instance, composite or host, now points to its child internal instances. To help visualize this, if a functional `<App>` component renders a `<Button>` class component, and `Button` class renders a `<div>`, the internal instance tree would look like this:
379+
As a result, each internal instance, composite or host, now points to its child internal instances. To help visualize this, if a function `<App>` component renders a `<Button>` class component, and `Button` class renders a `<div>`, the internal instance tree would look like this:
380380

381381
```js
382382
[object CompositeComponent] {

content/docs/legacy-context.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ If `contextTypes` is defined within a component, the following [lifecycle method
152152
>
153153
> As of React 16, `componentDidUpdate` no longer receives `prevContext`.
154154
155-
### Referencing Context in Stateless Functional Components
155+
### Referencing Context in Stateless Function Components
156156

157157
> This section documents a legacy API. See the [new API](/docs/context.html).
158158
159-
Stateless functional components are also able to reference `context` if `contextTypes` is defined as a property of the function. The following code shows a `Button` component written as a stateless functional component.
159+
Stateless function components are also able to reference `context` if `contextTypes` is defined as a property of the function. The following code shows a `Button` component written as a stateless function component.
160160

161161
```javascript
162162
import PropTypes from 'prop-types';

content/docs/reference-react-dom.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ When a component renders to `null` or `false`, `findDOMNode` returns `null`. Whe
9999
>
100100
> `findDOMNode` only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()` in `render()` on a component that has yet to be created) an exception will be thrown.
101101
>
102-
> `findDOMNode` cannot be used on functional components.
102+
> `findDOMNode` cannot be used on function components.
103103
104104
* * *
105105

content/docs/reference-test-renderer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Unmount the in-memory tree, triggering the appropriate lifecycle events.
142142
testRenderer.getInstance()
143143
```
144144

145-
Return the instance corresponding to the root element, if available. This will not work if the root element is a functional component because they don't have instances.
145+
Return the instance corresponding to the root element, if available. This will not work if the root element is a function component because they don't have instances.
146146

147147
### `testRenderer.root`
148148

@@ -206,7 +206,7 @@ Find all descendant test instances with the provided `props`.
206206
testInstance.instance
207207
```
208208

209-
The component instance corresponding to this test instance. It is only available for class components, as functional components don't have instances. It matches the `this` value inside the given component.
209+
The component instance corresponding to this test instance. It is only available for class components, as function components don't have instances. It matches the `this` value inside the given component.
210210

211211
### `testInstance.type`
212212

0 commit comments

Comments
 (0)