简体   繁体   English

我如何在本机反应中定义枚举

[英]How do i define an enum in react native

基本上我想要实现的是在没有引号的情况下将信息发送到服务器,例如 Admin 而不是“Admin”,但众所周知,Graphql 会抛出错误,因为变量未定义或不在引号中。

we can create a enum like property as below:我们可以创建一个类似枚举的属性,如下所示:

const adminEnum = { Admin: 'Admin'};

Hope I got the question right.希望我答对了。

I am using Enum in React as below method is Enum type in GraphQL我在 React 中使用 Enum,因为下面的method是 GraphQL 中的 Enum 类型

const result = apolloclient.mutate({
       mutation: reset_password,
       variables: {
           method: 'EMAIL',
           uuid: opts.uuid
       }
});

you can use enum with typeScript in react-native like describe in the link您可以在react-native使用 enum 和typeScript ,如链接中的描述

sample code is示例代码是

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}

枚举极{东=1,西,北,南,}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM