React 挖坑之旅

本文讲述了在使用create-react-app时遇到的四个问题:证书过期导致的npm错误,项目名称不能包含大写字母,img标签alt属性的重要性以及React18中componentDidMount的重复执行。提供了相应的解决方案和参考链接。
摘要由CSDN通过智能技术生成

一、request to https://registry.npm.taobao.org/create-react-app failed, reason: certificate has expired

使用npx create-react-app xxx时报错,这是由于我们的镜像问题

重新设置镜像

1.npm config set registry https://registry.npmmirror.com/

2.npm config get registry (查看是否成功)

3.npx create-react-app xxx

tips:(npx comes with npm 5.2+ and higher)

国内镜像最新地址参考网址:https://npmmirror.com/

二、name can no longer contain capital letters

使用npx create-react-app xxx时报错,这是很简单的问题,创建的React项目名称不要包含大写字母,这是因为npm的命名限制

三、img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.

这个的意思是img标签添加一个alt属性是一个非常好的习惯,防止任何错误引起的图片问题,Stack Overflow也有讨论到

javascript - What does this warning message mean? 'img elements must have an alt prop, either with meaningful text, or an empty string for decorative images' - Stack Overflow

四、React18 componentDidMount 重复执行两次的问题

将 index.tsx 或者 index.js 文件里的 React.StrictMode 高阶组件包围去掉即可

修改前

root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

修改后

root.render(
  //<React.StrictMode>
    <App />
  //</React.StrictMode>
);

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值