Skip to content

Commit deb63a7

Browse files
ref(js): Avoid using React.* (#7036)
In preperation for react 17 and 18
1 parent 2ae469c commit deb63a7

File tree

13 files changed

+41
-42
lines changed

13 files changed

+41
-42
lines changed

src/components/apiSidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {Fragment} from 'react';
22
import {useLocation} from '@reach/router';
33
import {graphql, useStaticQuery} from 'gatsby';
44

@@ -47,7 +47,7 @@ export default function ApiSidebar() {
4747
},
4848
children,
4949
}) => (
50-
<React.Fragment key={path}>
50+
<Fragment key={path}>
5151
<SidebarLink to={path} title={title} />
5252
{isActive(path) && (
5353
<div style={{paddingLeft: '0.5rem'}}>
@@ -65,7 +65,7 @@ export default function ApiSidebar() {
6565
)}
6666
</div>
6767
)}
68-
</React.Fragment>
68+
</Fragment>
6969
)
7070
)}
7171
</ul>

src/components/basePage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useRef} from 'react';
1+
import React, {forwardRef, Fragment, useRef} from 'react';
22

33
import {getCurrentTransaction} from '../utils';
44

@@ -24,7 +24,7 @@ type WrappedTOCProps = {
2424
pageContext: PageContext;
2525
};
2626

27-
const WrappedTOC = React.forwardRef(
27+
const WrappedTOC = forwardRef(
2828
(props: WrappedTOCProps, ref: React.RefObject<HTMLDivElement>) => {
2929
return <TableOfContents {...props} contentRef={ref} />;
3030
}
@@ -103,10 +103,10 @@ export default function BasePage({
103103
<div className="col-sm-4 col-md-12 col-lg-4 col-xl-3">
104104
<div className="page-nav">
105105
<Banner isModule />
106-
<React.Fragment>
106+
<Fragment>
107107
{prependToc}
108108
{hasToc && <WrappedTOC ref={contentRef} pageContext={pageContext} />}
109-
</React.Fragment>
109+
</Fragment>
110110
</div>
111111
</div>
112112
)}

src/components/codeBlock.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, {useContext, useRef, useState} from 'react';
2-
import ReactDOM from 'react-dom';
1+
import React, {Children, Fragment, useContext, useRef, useState} from 'react';
2+
import {createPortal} from 'react-dom';
33
import {ArrowDown, Clipboard} from 'react-feather';
44
import {usePopper} from 'react-popper';
55
import styled from '@emotion/styled';
@@ -14,7 +14,7 @@ import CodeContext from './codeContext';
1414
const KEYWORDS_REGEX = /\b___(?:([A-Z_][A-Z0-9_]*)\.)?([A-Z_][A-Z0-9_]*)___\b/g;
1515

1616
function makeKeywordsClickable(children: React.ReactChildren) {
17-
const items = React.Children.toArray(children);
17+
const items = Children.toArray(children);
1818

1919
KEYWORDS_REGEX.lastIndex = 0;
2020

@@ -102,7 +102,7 @@ function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
102102
const [isAnimating, setIsAnimating] = useState(false);
103103

104104
if (!currentSelection) {
105-
return <React.Fragment>keyword</React.Fragment>;
105+
return <Fragment>keyword</Fragment>;
106106
}
107107

108108
const selector = isOpen && (
@@ -135,7 +135,7 @@ function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
135135
const portal = getPortal();
136136

137137
return (
138-
<React.Fragment>
138+
<Fragment>
139139
<KeywordDropdown
140140
key={index}
141141
ref={setReferenceEl}
@@ -165,9 +165,8 @@ function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
165165
</AnimatePresence>
166166
</span>
167167
</KeywordDropdown>
168-
{portal &&
169-
ReactDOM.createPortal(<AnimatePresence>{selector}</AnimatePresence>, portal)}
170-
</React.Fragment>
168+
{portal && createPortal(<AnimatePresence>{selector}</AnimatePresence>, portal)}
169+
</Fragment>
171170
);
172171
}
173172

src/components/codeContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useState} from 'react';
1+
import {createContext, useEffect, useState} from 'react';
22

33
type ProjectCodeKeywords = {
44
API_URL: string;
@@ -68,7 +68,7 @@ type CodeContextType = {
6868
sharedKeywordSelection: any;
6969
};
7070

71-
const CodeContext = React.createContext<CodeContextType | null>(null);
71+
const CodeContext = createContext<CodeContextType | null>(null);
7272

7373
const parseDsn = function (dsn: string): Dsn {
7474
const match = dsn.match(/^(.*?\/\/)(.*?):(.*?)@(.*?)(\/.*?)$/);

src/components/navbarPlatformDropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {Fragment} from 'react';
22
import {NavDropdown} from 'react-bootstrap';
33
import {PlatformIcon} from 'platformicons';
44

@@ -12,15 +12,15 @@ export default function NavbarPlatformDropdown() {
1212
<NavDropdown
1313
title={
1414
currentPlatform ? (
15-
<React.Fragment>
15+
<Fragment>
1616
<PlatformIcon
1717
platform={currentPlatform.key}
1818
size={16}
1919
style={{marginRight: '0.5rem'}}
2020
format="lg"
2121
/>
2222
{currentPlatform.title}
23-
</React.Fragment>
23+
</Fragment>
2424
) : (
2525
'Platforms'
2626
)

src/components/pageContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
1+
import {createContext} from 'react';
22

33
type PageContextType = {
44
[key: string]: any;
55
};
66

7-
export const PageContext = React.createContext<null | PageContextType>(null);
7+
export const PageContext = createContext<null | PageContextType>(null);
88

99
export default PageContext;

src/components/platformContent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {Fragment, useState} from 'react';
22
import {graphql, useStaticQuery} from 'gatsby';
33

44
import usePlatform, {
@@ -71,7 +71,7 @@ export default function PlatformContent({
7171
const {
7272
allFile: {nodes: files},
7373
} = useStaticQuery(includeQuery);
74-
const [dropdown, setDropdown] = React.useState(null);
74+
const [dropdown, setDropdown] = useState(null);
7575
const [currentPlatform, setPlatform, isFixed] = usePlatform(platform);
7676
const hasDropdown = !isFixed;
7777

@@ -148,10 +148,10 @@ export default function PlatformContent({
148148

149149
<div className="tab-content">
150150
<div className="tab-pane show active">
151-
<React.Fragment>
151+
<Fragment>
152152
{children || null}
153153
<Content key={contentMatch.id} file={contentMatch} />
154-
</React.Fragment>
154+
</Fragment>
155155
</div>
156156
</div>
157157
</section>

src/components/platformSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {Fragment} from 'react';
22

33
import usePlatform, {getPlatformsWithFallback, Platform} from './hooks/usePlatform';
44

@@ -56,5 +56,5 @@ export default function PlatformSection({
5656
return null;
5757
}
5858

59-
return <React.Fragment>{children}</React.Fragment>;
59+
return <Fragment>{children}</Fragment>;
6060
}

src/components/relayMetrics.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {Fragment} from 'react';
22
import styled from '@emotion/styled';
33
import {graphql, useStaticQuery} from 'gatsby';
44

@@ -44,7 +44,7 @@ function Metric({metric}) {
4444
const descriptionHtml = metric.childRelayMetricDescription.childMarkdownRemark.html;
4545

4646
return (
47-
<React.Fragment>
47+
<Fragment>
4848
<dt>
4949
<code>
5050
{metric.name} <MetricType>({metric.type})</MetricType>
@@ -58,7 +58,7 @@ function Metric({metric}) {
5858
}}
5959
/>
6060
</dd>
61-
</React.Fragment>
61+
</Fragment>
6262
);
6363
}
6464

src/components/search.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useEffect, useRef, useState} from 'react';
1+
import React, {Fragment, useCallback, useEffect, useRef, useState} from 'react';
22
import {
33
Hit,
44
Result,
@@ -195,7 +195,7 @@ function Search({path, autoFocus, platforms = []}: Props): JSX.Element {
195195
{results
196196
.filter(x => x.hits.length > 0)
197197
.map((result, i) => (
198-
<React.Fragment key={result.site}>
198+
<Fragment key={result.site}>
199199
{showOffsiteResults && (
200200
<h4 className="sgs-site-result-heading">From {result.name}</h4>
201201
)}
@@ -255,7 +255,7 @@ function Search({path, autoFocus, platforms = []}: Props): JSX.Element {
255255
</li>
256256
))}
257257
</ul>
258-
</React.Fragment>
258+
</Fragment>
259259
))}
260260
</div>
261261
)}

0 commit comments

Comments
 (0)