微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

findDOMNode 在 StrictMode 中已弃用 findDOMNode 传递了一个 Transition 实例,该实例位于 StrictMode Material UI 中

如何解决findDOMNode 在 StrictMode 中已弃用 findDOMNode 传递了一个 Transition 实例,该实例位于 StrictMode Material UI 中

我有一个 React 组件

docker network prune

我使用 Material UI 进行样式设置,当我尝试在 Select 中选择 MenuItem 时出现错误

index.js:1 警告:在 StrictMode 中不推荐使用 findDOMNode。 findDOMNode 传递了一个内部的 Transition 实例 严格模式。相反,直接向你想要的元素添加一个 ref 参考。

我尝试通过 import React,{useRef,useState} from 'react'; import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import FormControl from '@material-ui/core/FormControl'; import Select from '@material-ui/core/Select'; import {useStyles} from './useStyles'; export const SelectField = ({modes,getSize}) => { const classes = useStyles(); const [size,setSize] = useState(0); const valuesArr = Object.values(modes).map(each => each.field); const nodeRef = useRef(null); const handleChange = (event) => { getSize(event.target.value) setSize(event.target.value); }; return ( <FormControl variant="outlined" className={classes.formControl}> <InputLabel id="demo-simple-select-outlined-label">Pick mode</InputLabel> <Select labelId="demo-simple-select-outlined-label" id="demo-simple-select-outlined" value={size} onChange={handleChange} label="Pick mode" className={classes.selectField} ref = {nodeRef} > {Object.keys(modes).map((mode,index) => <MenuItem value={valuesArr[index]} key = {mode + Date.Now()}>{mode}</MenuItem>)} </Select> </FormControl> ) } ref 添加Select const nodeRef = useRef(null) 但它没有帮助我。我知道如果我删除 ref = {nodeRef} 标签,这个问题就会消失,但我需要添加 <React.StrictMode></React.StrictMode>。有人可以帮我解决这个问题吗?提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。