简体   繁体   English

条件在本机生产中反应失败,但在开发中有效

[英]Condition fails in react native production, but works in development

I have created a react native app, by which I need compare from and to date.我创建了一个 React Native 应用程序,我需要通过它进行比较。 And if it's true, execution will be done.如果是真的,就会执行。

The problem is, the condition works in react native development mode and not working in react native production release.问题是,该条件适用于本机开发模式,而不适用于本机生产版本。 I am using firebase for the database, also using redux.我正在为数据库使用 firebase,也使用 redux。

Here is my code:这是我的代码:

  var d = new Date();
  const fromDate = extract.validFrom.split("-").reverse(); //"01-02-2019"
  const tillDate = extract.validTill.split("-").reverse(); //"10-03-2019"
  var k = new Date(fromDate)
  var j = new Date(tillDate)

The condition need to verified is :需要验证的条件是:

if(d.getDate() >= k.getDate() === true && d.getDate() <= j.getDate() === true){...some code}else{this.props.error("Code Expired")}

This works, absolutely fine while in development, but the condition is failing and moving to else.这有效,在开发过程中绝对没问题,但条件失败并转向其他。 I don't know why.我不知道为什么。 The form and till date is retired from firebase.表格和截止日期已从 firebase 中淘汰。

Please help me to solve.请帮我解决。

Actually this, happens because of different javascript core.实际上,这是由于不同的 javascript 核心而发生的。 As , chrome has latest version of core, but react native doesnt.由于,chrome 具有最新版本的核心,但 react native 没有。 So you need to give date as per ES6, change the date "01-02-2019" to所以你需要根据 ES6 给出日期,将日期“01-02-2019”更改为

"Fri Feb 02 2018 00:00:00 GMT+0530 (India Standard Time)". 

And after that, remove在那之后,删除

.split("-").reverse(); on both dates.

Hope Fully it will work.希望完全它会起作用。

Once I come across the same issue with date.一旦我遇到与日期相同的问题。 Then I have tried to enclose the value with new Date() and that helped me.然后我尝试用new Date()将值括起来,这对我有帮助。 I thought your problem is also similar to that.我认为你的问题也与此类似。 Try to compare as尝试比较为

if((new Date(d) >= new Date(k)) && (new Date(d) <= new Date(j))){
   ...some code
}

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

相关问题 反应助手导入在生产中失败,但在开发中工作 - react helper import fails in production but works in development React NPM 包(Dragula)可用于开发但不能用于生产 - React NPM package(Dragula) works in development but not in production React 组件未在生产构建中呈现,但在开发构建中按预期工作 - React component not rendering in production build but works as expected in development build 通过开发/生产ios目标应用程序响应本机用法 - React native usage with development / production ios target apps JavaScript在开发中发挥作用,而不在生产中发挥作用(Heroku) - JavaScript Works in Development, Not in Production (Heroku) React-开发和生产中的环境变量 - React - Env variables in development AND production React 应用程序无法通过其请求在生产中访问我的快速应用程序,但在开发中运行良好 - React app can't reach my express app in production with its requests but works fine in development React Framer motion animation 在开发中有效,但在生产构建中无效 - React Framer motion animation works in development but doesn't work in production build React.js 应用程序在开发模式下运行良好,但在构建(生产模式)后出现错误 - React.js app works fine in development mode but has errors after building (production mode) 地理位置开发工作不在生产中 - Geo-location works in development not in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM