Javascript 运行useEffect后不会重新分配变量

Javascript 运行useEffect后不会重新分配变量,javascript,react-native,react-hooks,Javascript,React Native,React Hooks,所以我在一开始就定义了这两个元素 let interestElm = ( <Row title={translate('calculator.interest')} value={translate('currency_amount', { amount: offer.totalInterest, })} /> ); let commisionElm = ( <Row title={

所以我在一开始就定义了这两个元素

let interestElm = (
    <Row
      title={translate('calculator.interest')}
      value={translate('currency_amount', {
        amount: offer.totalInterest,
      })}
    />
  );
  let commisionElm = (
    <Row
      title={translate('calculator.commission')}
      value={translate('currency_amount', {
        amount: offer.newInitialCommission,
      })}
    />
  ); 
此函数检查某些值,如果这些值存在,则应重新分配变量

const discountElemHandler = (discount) => {
    if (discount.length) {
      discount.forEach(discountItem => {
        if (discountItem.type === 'Type1') {
          interestElm = (
            <Row
              inheritStyle={style.discount}
              title={translate('calculator.interest')}
              discount={translate('currency_amount', {
                amount: offer.newInterest + discountItem.amount,
              })}
              value={translate('currency_amount', {
                amount: offer.totalInterest,
              })}
            />
          );
        }

        if (discountItem.type === 'Type2') {
          commisionElm = (
            <Row
              inheritStyle={style.discount}
              title={translate('calculator.commission')}
              discount={translate('currency_amount', {
                amount: offer.newInitialCommission + discountItem.amount,
              })}
              value={translate('currency_amount', {
                amount: offer.newInitialCommission,
              })}
            />
          );
        }
      });
    }
  };
const discountElemHandler=(折扣)=>{
if(折扣长度){
折扣。forEach(折扣项=>{
如果(discountItem.type=='Type1'){
利息M=(
);
}
如果(discountItem.type=='Type2'){
佣金=(
);
}
});
}
};
我可以在调试器上看到函数满足了条件,但由于某种原因,没有重新分配

有人能帮我吗?
谢谢加载

在渲染方法在屏幕上完成绘制后,将调用useEffect。这意味着,如果希望在运行useEffect后触发新渲染,则需要触发状态更改。
我建议您要么将两个let变量定义为STATE,要么在STATE中存储其他类型的数据,这将在这两个变量中使用。

这是否回答了您的问题@JaredSmith问题不在于状态,因为元素中的大多数数据都是从状态呈现的,因此当状态发生变化时,它应该自动调用重新呈现,但即使我将整个elm置于状态,我仍然面临相同的问题!如果您提供RENDER方法,这将非常有用,这样我们可以看到您实际渲染的内容/方式JSX@LamisAbouzina您试图修改一个封闭变量,而不是将其置于状态,这意味着它是另一个变量的副本。实际上,提供、折扣、折扣数据和元素的几乎所有部分都来自多个状态
const discountElemHandler = (discount) => {
    if (discount.length) {
      discount.forEach(discountItem => {
        if (discountItem.type === 'Type1') {
          interestElm = (
            <Row
              inheritStyle={style.discount}
              title={translate('calculator.interest')}
              discount={translate('currency_amount', {
                amount: offer.newInterest + discountItem.amount,
              })}
              value={translate('currency_amount', {
                amount: offer.totalInterest,
              })}
            />
          );
        }

        if (discountItem.type === 'Type2') {
          commisionElm = (
            <Row
              inheritStyle={style.discount}
              title={translate('calculator.commission')}
              discount={translate('currency_amount', {
                amount: offer.newInitialCommission + discountItem.amount,
              })}
              value={translate('currency_amount', {
                amount: offer.newInitialCommission,
              })}
            />
          );
        }
      });
    }
  };