react学习历程问题记载(一)

10、 Mac 新建react项目 create-react-app: command not found
变更create-react-app my-app 为 npm init react-app my-app

9、 Too many re-renders. React limits the number of renders to prevent an infinite loop.
原因:最底层组件在定义变量后直接set变量导致死循环。
解决:去掉set行即可。

8、React Hook useEffect has a missing dependency: 'props.menuData'. Either include it or remove the dependency array. 
If 'setMenuSiderData' needs the current value of 'props.menuData', you can also switch to useReducer instead of useState and read 'props.men 解决:【未解决】 7、 react + Echarts5.0.2 图表显示不出来,降版本为Echarts4.1.0。 6、Error: Function components cannot have string refs. We recommend using useRef() instead. 解决:去除dom节点中的ref属性 5、函数式组件变量定义和周期使用 import React, { useState, useEffect } from 'react'; const [count, setCount] = useState(0); useEffect(() => { console.log('某地区蒸发量和降水量'); }); 4、记录:
样式class定义变更为className。
函数式组件名称首字母必须大写。 组件首字母大写,元素首字母小写。 3、react map循环一直报Expected to return a value in arrow function array-callback-return警告 解决: 1)用Object.keys(this.props.obj).forEach去替换.map,因为ESLint array-callback-return这个警告是因为在使用map, filter , reduce 没有去返回一个值。 2)如果使用map,在react中用jsx的方式,直接把{}改成()即可。 2、函数式组件没有生命周期 原因:函数式组件没有继承React.Component,由于生命周期函数是React.Component类的方法实现的,所以没继承这个类,自然就没法使用生命周期函数了 1、Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Wave which is inside StrictMode.
Instead, add a ref directly to the element you want to reference.
Learn more about using refs safely here: https://fb.me/react-strict-mode-find-node
原因: react 中的严格模式: StrictMode 解决: 在 index.js中去除React.StrictMode标签
原文地址:https://www.cnblogs.com/min77/p/14605268.html