Skip to content

Commit 40a521a

Browse files
authored
Terminology: Functional -> Function Component (#13775)
* Terminology: Functional -> Function Component * Drop the "stateless" (functions are already stateless, right?)
1 parent 605ab10 commit 40a521a

30 files changed

Lines changed: 157 additions & 165 deletions

packages/react-dom/src/__tests__/ReactDOM-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ describe('ReactDOM', () => {
387387
}
388388
});
389389

390-
it('should not crash calling findDOMNode inside a functional component', () => {
390+
it('should not crash calling findDOMNode inside a function component', () => {
391391
const container = document.createElement('div');
392392

393393
class Component extends React.Component {

packages/react-dom/src/__tests__/ReactDOMServerIntegrationElements-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ describe('ReactDOMServerIntegration', () => {
623623
}
624624

625625
itRenders('stateless components', async render => {
626-
const StatelessComponent = () => <div>foo</div>;
627-
checkFooDiv(await render(<StatelessComponent />));
626+
const FunctionComponent = () => <div>foo</div>;
627+
checkFooDiv(await render(<FunctionComponent />));
628628
});
629629

630630
itRenders('ES6 class components', async render => {

packages/react-dom/src/__tests__/ReactDOMServerIntegrationLegacyContext-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ describe('ReactDOMServerIntegration', () => {
7676
});
7777

7878
itRenders('stateless child with context', async render => {
79-
function StatelessChildWithContext(props, context) {
79+
function FunctionChildWithContext(props, context) {
8080
return <div>{context.text}</div>;
8181
}
82-
StatelessChildWithContext.contextTypes = {text: PropTypes.string};
82+
FunctionChildWithContext.contextTypes = {text: PropTypes.string};
8383

8484
const e = await render(
8585
<PurpleContext>
86-
<StatelessChildWithContext />
86+
<FunctionChildWithContext />
8787
</PurpleContext>,
8888
);
8989
expect(e.textContent).toBe('purple');
@@ -106,14 +106,14 @@ describe('ReactDOMServerIntegration', () => {
106106
});
107107

108108
itRenders('stateless child without context', async render => {
109-
function StatelessChildWithoutContext(props, context) {
109+
function FunctionChildWithoutContext(props, context) {
110110
// this should render blank; context isn't passed to this component.
111111
return <div>{context.text}</div>;
112112
}
113113

114114
const e = await render(
115115
<PurpleContext>
116-
<StatelessChildWithoutContext />
116+
<FunctionChildWithoutContext />
117117
</PurpleContext>,
118118
);
119119
expect(e.textContent).toBe('');
@@ -137,17 +137,17 @@ describe('ReactDOMServerIntegration', () => {
137137
});
138138

139139
itRenders('stateless child with wrong context', async render => {
140-
function StatelessChildWithWrongContext(props, context) {
140+
function FunctionChildWithWrongContext(props, context) {
141141
// this should render blank; context.text isn't passed to this component.
142142
return <div id="statelessWrongChild">{context.text}</div>;
143143
}
144-
StatelessChildWithWrongContext.contextTypes = {
144+
FunctionChildWithWrongContext.contextTypes = {
145145
foo: PropTypes.string,
146146
};
147147

148148
const e = await render(
149149
<PurpleContext>
150-
<StatelessChildWithWrongContext />
150+
<FunctionChildWithWrongContext />
151151
</PurpleContext>,
152152
);
153153
expect(e.textContent).toBe('');

packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ describe('ReactDOMServerIntegration', () => {
7575
});
7676

7777
itRenders('stateless child with context', async render => {
78-
function StatelessChildWithContext(props) {
78+
function FunctionChildWithContext(props) {
7979
return <Consumer>{text => text}</Consumer>;
8080
}
8181

8282
const e = await render(
8383
<PurpleContext>
84-
<StatelessChildWithContext />
84+
<FunctionChildWithContext />
8585
</PurpleContext>,
8686
);
8787
expect(e.textContent).toBe('purple');
@@ -103,15 +103,15 @@ describe('ReactDOMServerIntegration', () => {
103103
});
104104

105105
itRenders('stateless child with wrong context', async render => {
106-
function StatelessChildWithWrongContext(props) {
106+
function FunctionChildWithWrongContext(props) {
107107
return (
108108
<div id="statelessWrongChild">
109109
<Consumer>{text => text}</Consumer>
110110
</div>
111111
);
112112
}
113113

114-
const e = await render(<StatelessChildWithWrongContext />);
114+
const e = await render(<FunctionChildWithWrongContext />);
115115
expect(e.textContent).toBe('none');
116116
});
117117

packages/react-dom/src/__tests__/ReactStatelessComponent-test.js renamed to packages/react-dom/src/__tests__/ReactFunctionComponent-test.js

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ let React;
1414
let ReactDOM;
1515
let ReactTestUtils;
1616

17-
function StatelessComponent(props) {
17+
function FunctionComponent(props) {
1818
return <div>{props.name}</div>;
1919
}
2020

21-
describe('ReactStatelessComponent', () => {
21+
describe('ReactFunctionComponent', () => {
2222
beforeEach(() => {
2323
jest.resetModuleRegistry();
2424
PropTypes = require('prop-types');
@@ -29,15 +29,15 @@ describe('ReactStatelessComponent', () => {
2929

3030
it('should render stateless component', () => {
3131
const el = document.createElement('div');
32-
ReactDOM.render(<StatelessComponent name="A" />, el);
32+
ReactDOM.render(<FunctionComponent name="A" />, el);
3333

3434
expect(el.textContent).toBe('A');
3535
});
3636

3737
it('should update stateless component', () => {
3838
class Parent extends React.Component {
3939
render() {
40-
return <StatelessComponent {...this.props} />;
40+
return <FunctionComponent {...this.props} />;
4141
}
4242
}
4343

@@ -52,7 +52,7 @@ describe('ReactStatelessComponent', () => {
5252
it('should unmount stateless component', () => {
5353
const container = document.createElement('div');
5454

55-
ReactDOM.render(<StatelessComponent name="A" />, container);
55+
ReactDOM.render(<FunctionComponent name="A" />, container);
5656
expect(container.textContent).toBe('A');
5757

5858
ReactDOM.unmountComponentAtNode(container);
@@ -98,42 +98,42 @@ describe('ReactStatelessComponent', () => {
9898
expect(el.textContent).toBe('mest');
9999
});
100100

101-
it('should warn for getDerivedStateFromProps on a functional component', () => {
102-
function StatelessComponentWithChildContext() {
101+
it('should warn for getDerivedStateFromProps on a function component', () => {
102+
function FunctionComponentWithChildContext() {
103103
return null;
104104
}
105-
StatelessComponentWithChildContext.getDerivedStateFromProps = function() {};
105+
FunctionComponentWithChildContext.getDerivedStateFromProps = function() {};
106106

107107
const container = document.createElement('div');
108108

109109
expect(() =>
110-
ReactDOM.render(<StatelessComponentWithChildContext />, container),
110+
ReactDOM.render(<FunctionComponentWithChildContext />, container),
111111
).toWarnDev(
112-
'StatelessComponentWithChildContext: Stateless ' +
113-
'functional components do not support getDerivedStateFromProps.',
112+
'FunctionComponentWithChildContext: Function ' +
113+
'components do not support getDerivedStateFromProps.',
114114
{withoutStack: true},
115115
);
116116
});
117117

118-
it('should warn for childContextTypes on a functional component', () => {
119-
function StatelessComponentWithChildContext(props) {
118+
it('should warn for childContextTypes on a function component', () => {
119+
function FunctionComponentWithChildContext(props) {
120120
return <div>{props.name}</div>;
121121
}
122122

123-
StatelessComponentWithChildContext.childContextTypes = {
123+
FunctionComponentWithChildContext.childContextTypes = {
124124
foo: PropTypes.string,
125125
};
126126

127127
const container = document.createElement('div');
128128

129129
expect(() =>
130130
ReactDOM.render(
131-
<StatelessComponentWithChildContext name="A" />,
131+
<FunctionComponentWithChildContext name="A" />,
132132
container,
133133
),
134134
).toWarnDev(
135-
'StatelessComponentWithChildContext(...): childContextTypes cannot ' +
136-
'be defined on a functional component.',
135+
'FunctionComponentWithChildContext(...): childContextTypes cannot ' +
136+
'be defined on a function component.',
137137
{withoutStack: true},
138138
);
139139
});
@@ -161,12 +161,12 @@ describe('ReactStatelessComponent', () => {
161161
ReactTestUtils.renderIntoDocument(<Child test="test" />);
162162
}).toThrowError(
163163
__DEV__
164-
? 'Stateless function components cannot have refs.'
164+
? 'Function components cannot have refs.'
165165
: // It happens because we don't save _owner in production for
166-
// functional components.
166+
// function components.
167167
'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
168168
' the following reasons:\n' +
169-
'1. You may be adding a ref to a functional component\n' +
169+
'1. You may be adding a ref to a function component\n' +
170170
"2. You may be adding a ref to a component that was not created inside a component's render method\n" +
171171
'3. You have multiple copies of React loaded\n' +
172172
'See https://fb.me/react-refs-must-have-owner for more information.',
@@ -182,7 +182,7 @@ describe('ReactStatelessComponent', () => {
182182
render() {
183183
return (
184184
<Indirection>
185-
<StatelessComponent name="A" ref="stateless" />
185+
<FunctionComponent name="A" ref="stateless" />
186186
</Indirection>
187187
);
188188
}
@@ -191,10 +191,10 @@ describe('ReactStatelessComponent', () => {
191191
expect(() =>
192192
ReactTestUtils.renderIntoDocument(<ParentUsingStringRef />),
193193
).toWarnDev(
194-
'Warning: Stateless function components cannot be given refs. ' +
194+
'Warning: Function components cannot be given refs. ' +
195195
'Attempts to access this ref will fail.\n\nCheck the render method ' +
196196
'of `ParentUsingStringRef`.\n' +
197-
' in StatelessComponent (at **)\n' +
197+
' in FunctionComponent (at **)\n' +
198198
' in div (at **)\n' +
199199
' in Indirection (at **)\n' +
200200
' in ParentUsingStringRef (at **)',
@@ -213,7 +213,7 @@ describe('ReactStatelessComponent', () => {
213213
render() {
214214
return (
215215
<Indirection>
216-
<StatelessComponent
216+
<FunctionComponent
217217
name="A"
218218
ref={arg => {
219219
expect(arg).toBe(null);
@@ -227,10 +227,10 @@ describe('ReactStatelessComponent', () => {
227227
expect(() =>
228228
ReactTestUtils.renderIntoDocument(<ParentUsingFunctionRef />),
229229
).toWarnDev(
230-
'Warning: Stateless function components cannot be given refs. ' +
230+
'Warning: Function components cannot be given refs. ' +
231231
'Attempts to access this ref will fail.\n\nCheck the render method ' +
232232
'of `ParentUsingFunctionRef`.\n' +
233-
' in StatelessComponent (at **)\n' +
233+
' in FunctionComponent (at **)\n' +
234234
' in div (at **)\n' +
235235
' in Indirection (at **)\n' +
236236
' in ParentUsingFunctionRef (at **)',
@@ -244,7 +244,7 @@ describe('ReactStatelessComponent', () => {
244244
// When owner uses JSX, we can use exact line location to dedupe warnings
245245
class AnonymousParentUsingJSX extends React.Component {
246246
render() {
247-
return <StatelessComponent name="A" ref={() => {}} />;
247+
return <FunctionComponent name="A" ref={() => {}} />;
248248
}
249249
}
250250
Object.defineProperty(AnonymousParentUsingJSX, 'name', {value: undefined});
@@ -255,9 +255,7 @@ describe('ReactStatelessComponent', () => {
255255
instance1 = ReactTestUtils.renderIntoDocument(
256256
<AnonymousParentUsingJSX />,
257257
);
258-
}).toWarnDev(
259-
'Warning: Stateless function components cannot be given refs.',
260-
);
258+
}).toWarnDev('Warning: Function components cannot be given refs.');
261259
// Should be deduped (offending element is on the same line):
262260
instance1.forceUpdate();
263261
// Should also be deduped (offending element is on the same line):
@@ -266,7 +264,7 @@ describe('ReactStatelessComponent', () => {
266264
// When owner doesn't use JSX, and is anonymous, we warn once per internal instance.
267265
class AnonymousParentNotUsingJSX extends React.Component {
268266
render() {
269-
return React.createElement(StatelessComponent, {
267+
return React.createElement(FunctionComponent, {
270268
name: 'A',
271269
ref: () => {},
272270
});
@@ -281,20 +279,18 @@ describe('ReactStatelessComponent', () => {
281279
instance2 = ReactTestUtils.renderIntoDocument(
282280
<AnonymousParentNotUsingJSX />,
283281
);
284-
}).toWarnDev(
285-
'Warning: Stateless function components cannot be given refs.',
286-
);
282+
}).toWarnDev('Warning: Function components cannot be given refs.');
287283
// Should be deduped (same internal instance, no additional warnings)
288284
instance2.forceUpdate();
289285
// Could not be deduped (different internal instance):
290286
expect(() =>
291287
ReactTestUtils.renderIntoDocument(<AnonymousParentNotUsingJSX />),
292-
).toWarnDev('Warning: Stateless function components cannot be given refs.');
288+
).toWarnDev('Warning: Function components cannot be given refs.');
293289

294290
// When owner doesn't use JSX, but is named, we warn once per owner name
295291
class NamedParentNotUsingJSX extends React.Component {
296292
render() {
297-
return React.createElement(StatelessComponent, {
293+
return React.createElement(FunctionComponent, {
298294
name: 'A',
299295
ref: () => {},
300296
});
@@ -303,9 +299,7 @@ describe('ReactStatelessComponent', () => {
303299
let instance3;
304300
expect(() => {
305301
instance3 = ReactTestUtils.renderIntoDocument(<NamedParentNotUsingJSX />);
306-
}).toWarnDev(
307-
'Warning: Stateless function components cannot be given refs.',
308-
);
302+
}).toWarnDev('Warning: Function components cannot be given refs.');
309303
// Should be deduped (same owner name, no additional warnings):
310304
instance3.forceUpdate();
311305
// Should also be deduped (same owner name, no additional warnings):
@@ -337,7 +331,7 @@ describe('ReactStatelessComponent', () => {
337331
}
338332

339333
expect(() => ReactTestUtils.renderIntoDocument(<Parent />)).toWarnDev(
340-
'Warning: Stateless function components cannot be given refs. ' +
334+
'Warning: Function components cannot be given refs. ' +
341335
'Attempts to access this ref will fail.\n\nCheck the render method ' +
342336
'of `Parent`.\n' +
343337
' in Child (at **)\n' +

packages/react-dom/src/__tests__/ReactTestUtils-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ describe('ReactTestUtils', () => {
259259
});
260260

261261
it('can scry with stateless components involved', () => {
262-
const Stateless = () => (
262+
const Function = () => (
263263
<div>
264264
<hr />
265265
</div>
@@ -269,7 +269,7 @@ describe('ReactTestUtils', () => {
269269
render() {
270270
return (
271271
<div>
272-
<Stateless />
272+
<Function />
273273
<hr />
274274
</div>
275275
);

packages/react-dom/src/__tests__/multiple-copies-of-react-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('when different React version is used with string ref', () => {
2727
}).toThrow(
2828
'Element ref was specified as a string (foo) but no owner was set. This could happen for one of' +
2929
' the following reasons:\n' +
30-
'1. You may be adding a ref to a functional component\n' +
30+
'1. You may be adding a ref to a function component\n' +
3131
"2. You may be adding a ref to a component that was not created inside a component's render method\n" +
3232
'3. You have multiple copies of React loaded\n' +
3333
'See https://fb.me/react-refs-must-have-owner for more information.',

packages/react-dom/src/__tests__/refs-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ describe('creating element with ref in constructor', () => {
444444
}).toThrowError(
445445
'Element ref was specified as a string (p) but no owner was set. This could happen for one of' +
446446
' the following reasons:\n' +
447-
'1. You may be adding a ref to a functional component\n' +
447+
'1. You may be adding a ref to a function component\n' +
448448
"2. You may be adding a ref to a component that was not created inside a component's render method\n" +
449449
'3. You have multiple copies of React loaded\n' +
450450
'See https://fb.me/react-refs-must-have-owner for more information.',

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import * as ReactInstanceMap from 'shared/ReactInstanceMap';
1212
import {
1313
ClassComponent,
1414
ClassComponentLazy,
15-
FunctionalComponent,
16-
FunctionalComponentLazy,
15+
FunctionComponent,
16+
FunctionComponentLazy,
1717
HostComponent,
1818
HostText,
1919
} from 'shared/ReactWorkTags';
@@ -93,8 +93,8 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
9393
node.tag === HostText ||
9494
node.tag === ClassComponent ||
9595
node.tag === ClassComponentLazy ||
96-
node.tag === FunctionalComponent ||
97-
node.tag === FunctionalComponentLazy
96+
node.tag === FunctionComponent ||
97+
node.tag === FunctionComponentLazy
9898
) {
9999
const publicInst = node.stateNode;
100100
if (test(publicInst)) {

0 commit comments

Comments
 (0)