Skip to content

Commit

Permalink
TranslationProvider [nfc]: Annotate TranslationContext.
Browse files Browse the repository at this point in the history
Despite passing `undefined` as the `defaultValue` argument to
`React.createContext`, consumers will never see `undefined` as the
value for `this.context` or `useContext(TranslationContext)`.

That is, as long as `TranslationContext.Provider` is above such
consumers in the component hierarchy. From React's doc on
`createContext` [1],

"""
The `defaultValue` argument is **only** used when a component does
not have a matching Provider above it in the tree. This can be
helpful for testing components in isolation without wrapping them.
"""

Adding this annotation will satisfy the new version of Flow
(0.122.0) that we'll get along with the React Native v0.63 upgrade
(zulip#4245) soon.

[1] https://reactjs.org/docs/context.html#reactcreatecontext
  • Loading branch information
chrisbobbe committed Jan 14, 2021
1 parent 45e330c commit 6a5b35e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/boot/TranslationProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow strict-local */
import React, { PureComponent } from 'react';
import React, { PureComponent, type Context } from 'react';
import type { ComponentType, ElementConfig, Node as React$Node } from 'react';
import { Text } from 'react-native';
import { IntlProvider, IntlContext } from 'react-intl';
Expand All @@ -11,7 +11,7 @@ import { getSettings } from '../selectors';
import messages from '../i18n/messages';

// $FlowFixMe could put a well-typed mock value here, to help write tests
export const TranslationContext = React.createContext(undefined);
export const TranslationContext: Context<GetText> = React.createContext(undefined);

/**
* Provide `_` to the wrapped component, passing other props through.
Expand Down

0 comments on commit 6a5b35e

Please sign in to comment.