Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6208

Adding non-nullable static type to memoized components throws lint error, see example for clarity

$
0
0

Example 1.

Non-nullable someStaticProperty, this will throw a lint error

import { NamedExoticComponent, memo } from "react";

type WithComponentId = { componentId: string };

type ScreenComponentStaticMembers = {
  someStaticProperty: string;
};

type AliasedType<P = {}> = NamedExoticComponent<P & WithComponentId> &
  ScreenComponentStaticMembers;

type MyComponentProps = {
  greeting: string;
};

const MyComponent: AliasedType<MyComponentProps> = memo(({ greeting }) => (
  <span>{greeting} there!</span>
));

MyComponent.someStaticProperty = "baz";

Example 2.

Optional someStaticProperty, this will work.

import { NamedExoticComponent, memo } from "react";

type WithComponentId = { componentId: string };

type ScreenComponentStaticMembers = {
  someStaticProperty?: string;
};

type AliasedType<P = {}> = NamedExoticComponent<P & WithComponentId> &
  ScreenComponentStaticMembers;

type MyComponentProps = {
  greeting: string;
};

const MyComponent: AliasedType<MyComponentProps> = memo(({ greeting }) => (
  <span>{greeting} there!</span>
));

MyComponent.someStaticProperty = "baz";

Viewing all articles
Browse latest Browse all 6208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>