Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 元素ref被指定为字符串(映射),但未设置所有者_Reactjs - Fatal编程技术网

Reactjs 元素ref被指定为字符串(映射),但未设置所有者

Reactjs 元素ref被指定为字符串(映射),但未设置所有者,reactjs,Reactjs,我已将我的项目更新为React 16.3.1,现在出现以下错误: Uncaught Error: Element ref was specified as a string (map) but no owner was set. You may have multiple copies of React loaded. (details: https://fb(dot)me/react-refs-must-have-owner). at invariant (invariant.js:4

我已将我的项目更新为React 16.3.1,现在出现以下错误:

Uncaught Error: Element ref was specified as a string (map) but no owner was set. You may have multiple copies of React loaded. (details: https://fb(dot)me/react-refs-must-have-owner).
    at invariant (invariant.js:42)
    at coerceRef (react-dom.development.js:6736)
    at createChild (react-dom.development.js:6977)
    at reconcileChildrenArray (react-dom.development.js:7282)
    at reconcileChildFibers (react-dom.development.js:7651)
    at reconcileChildrenAtExpirationTime (react-dom.development.js:7756)
    at reconcileChildren (react-dom.development.js:7747)
    at updateHostComponent (react-dom.development.js:7998)
    at beginWork (react-dom.development.js:8229)
    at performUnitOfWork (react-dom.development.js:10224)
    at workLoop (react-dom.development.js:10288)
    at HTMLUnknownElement.callCallback (react-dom.development.js:542)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
    at invokeGuardedCallback (react-dom.development.js:438)
    at renderRoot (react-dom.development.js:10366)
    at performWorkOnRoot (react-dom.development.js:11014)
    at performWork (react-dom.development.js:10967)
    at requestWork (react-dom.development.js:10878)
    at scheduleWorkImpl (react-dom.development.js:10732)
    at scheduleWork (react-dom.development.js:10689)
    at Object.enqueueSetState (react-dom.development.js:6212)
    at Wrapper.../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:242)
    at Wrapper.onLoad (GoogleApiComponent.js:194)
    at ScriptCache.js:39
我是一个完全的新手,所以我不确定我到底应该寻找什么来发现错误

注:当我运行
npm ls react
时,我已排除了多副本选项,因为我得到:

└── react@16.3.1

根据react关于版本16.3更改的文档,旧的字符串ref api已被弃用,现在您应该使用ref回调api,如下所示

类MyComponent扩展了React.Component{ 建造师(道具){ 超级(道具); this.inputRef=React.createRef(); } render(){ 返回; } componentDidMount(){ this.inputRef.current.focus(); }
}根据react关于版本16.3更改的文档,旧的字符串ref api已被弃用,现在您应该使用ref回调api,如下所示

类MyComponent扩展了React.Component{ 建造师(道具){ 超级(道具); this.inputRef=React.createRef(); } render(){ 返回; } componentDidMount(){ this.inputRef.current.focus(); }
}您是否检查了
16.3.1
ref
createRef();
)的以下更改:如果出现错误,我应该查找哪个字符串?您能将相关代码放在这里吗?不幸的是,我未经授权。你会寻找什么?确保你也更新了
react dom
,可能会尝试删除node_模块并运行
npm install
你是否检查了
16.3.1
ref
createRef();
)的以下更改:鉴于错误,我应该找哪个字符串?你能把相关的代码放在这里吗?很遗憾我没有授权。你会寻找什么?确保你也更新了
react-dom
,可能会尝试删除节点模块并运行
npm-install