gpt4 book ai didi

reactjs - 尝试初始化 react 属性时出现问题

转载 作者:行者123 更新时间:2023-12-05 02:25:47 25 4
gpt4 key购买 nike

问题详情

  1. .env value not initialized in the react property
  2. siteKey value is always blank

react 中的属性

const [siteKey] = useState(process.env.REACT_CAPTCHA_SITE_KEY);

输入.env

REACT_CAPTCHA_SITE_KEY='some key'

HTML

<ReCAPTCHA sitekey={siteKey}/>

最佳答案

主要问题是您的环境声明,根据 create-react-app :

You must create custom environment variables beginning withREACT_APP_. Any other variables except NODE_ENV will be ignored toavoid accidentally exposing a private key on the machine that couldhave the same name. Changing any environment variables will requireyou to restart the development server if it is running.

由于您没有useState 所需的任何setter 方法,您可以只使用const 定义您的变量,例如:

const siteKey = process.env.REACT_APP_CAPTCHA_SITE_KEY

关于reactjs - 尝试初始化 react 属性时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74305961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com