Skip to content

Commit 30ed5ea

Browse files
chrisbobbegnprice
authored andcommitted
TranslationProvider [nfc]: Use import * as React style
For some reason after the upcoming `yarn upgrade`, ESLint would give these errors: /Users/chrisbobbe/dev/zulip-mobile/src/boot/TranslationProvider.js 2:49 error '/Users/chrisbobbe/dev/zulip-mobile/node_modules/react/index.js' imported multiple times import/no-duplicates 3:57 error '/Users/chrisbobbe/dev/zulip-mobile/node_modules/react/index.js' imported multiple times import/no-duplicates ✖ 2 problems (2 errors, 0 warnings) So prevent those errors by doing this.
1 parent b0a3983 commit 30ed5ea

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/boot/TranslationProvider.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* @flow strict-local */
2-
import React, { type Context, useContext } from 'react';
3-
import type { ComponentType, ElementConfig, Node } from 'react';
2+
import * as React from 'react';
43
import { Text } from 'react-native';
54
import { IntlProvider, IntlContext } from 'react-intl';
65
import type { IntlShape } from 'react-intl';
@@ -11,7 +10,7 @@ import { getGlobalSettings } from '../selectors';
1110
import messages from '../i18n/messages';
1211

1312
// $FlowFixMe[incompatible-type] could put a well-typed mock value here, to help write tests
14-
export const TranslationContext: Context<GetText> = React.createContext(undefined);
13+
export const TranslationContext: React.Context<GetText> = React.createContext(undefined);
1514

1615
/**
1716
* Provide `_` to the wrapped component, passing other props through.
@@ -21,11 +20,11 @@ export const TranslationContext: Context<GetText> = React.createContext(undefine
2120
* simply saying `context: TranslationContext` may be more convenient.
2221
* Or in a function component, `const _ = useContext(TranslationContext);`.
2322
*/
24-
export function withGetText<P: { +_: GetText, ... }, C: ComponentType<P>>(
23+
export function withGetText<P: { +_: GetText, ... }, C: React.ComponentType<P>>(
2524
WrappedComponent: C,
26-
): ComponentType<$ReadOnly<$Exact<$Diff<ElementConfig<C>, {| _: GetText |}>>>> {
25+
): React.ComponentType<$ReadOnly<$Exact<$Diff<React.ElementConfig<C>, {| _: GetText |}>>>> {
2726
// eslint-disable-next-line func-names
28-
return function (props: $Exact<$Diff<ElementConfig<C>, {| _: GetText |}>>): Node {
27+
return function (props: $Exact<$Diff<React.ElementConfig<C>, {| _: GetText |}>>): React.Node {
2928
return (
3029
<TranslationContext.Consumer>
3130
{_ => <WrappedComponent _={_} {...props} />}
@@ -61,8 +60,8 @@ const makeGetText = (intl: IntlShape): GetText => {
6160
*
6261
* See the `GetTypes` type for why we like the new shape.
6362
*/
64-
function TranslationContextTranslator(props: {| +children: Node |}): Node {
65-
const intlContextValue = useContext(IntlContext);
63+
function TranslationContextTranslator(props: {| +children: React.Node |}): React.Node {
64+
const intlContextValue = React.useContext(IntlContext);
6665

6766
return (
6867
<TranslationContext.Provider value={makeGetText(intlContextValue)}>
@@ -72,10 +71,10 @@ function TranslationContextTranslator(props: {| +children: Node |}): Node {
7271
}
7372

7473
type Props = $ReadOnly<{|
75-
children: Node,
74+
children: React.Node,
7675
|}>;
7776

78-
export default function TranslationProvider(props: Props): Node {
77+
export default function TranslationProvider(props: Props): React.Node {
7978
const { children } = props;
8079
const language = useGlobalSelector(state => getGlobalSettings(state).language);
8180

0 commit comments

Comments
 (0)