Issue
I have an react native fabric native components. I'm trying to have in the Javascript Specification file a enum or type as follow: Im getting an error when running codegen when using SizeType in the NativeProps interface.
Error: A default enum value is required for "size"
Is there a way to use Enums or types like this? (If i dont use SizeType in the NativeProps the codegen running with no error).
Appreciate your answer.
import type { HostComponent } from "react-native";
import { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
type SizeType = "s" | "m" | "l"
export interface NativeProps extends ViewProps {
title: string;
size: SizeType;
}
export default codegenNativeComponent<NativeProps>(
"RTNButtonView"
) as HostComponent<NativeProps>;
i tries to use type or enum
Solution
You can solve this issue using the type WithDefault
type provided in react-native/Libraries/Types/CodegenTypes
.
You code should be the following:
import type { HostComponent } from "react-native";
import { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
type SizeType = "s" | "m" | "l"
export interface NativeProps extends ViewProps {
title: string;
size?: WithDefault<SizeType, 'm'>;
}
export default codegenNativeComponent<NativeProps>(
"RTNButtonView"
) as HostComponent<NativeProps>;
Note that the ?
mark is important when using WithDefault
Answered By - Abderrahim Ajakka
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.