javascript - 警告:在严格模式树中发现了一个字符串 ref,'code'。字符串引用是潜在错误的来源,应该避免
问题描述
我正在尝试使用 将一些代码片段放在页面中react-highlight
,按照其文档,我编写了以下代码:
<Highlight className='javascript'>
{
<div children={`import React from 'react';
import './Hello.scss';
const Hello = () => {
return (
<>
<div>
Hello world!
</div>
</>
)
}
export default Hello;`}/>
}
</Highlight>
它运行良好并提供语法突出显示。但是,我收到以下控制台警告:
Warning: A string ref, "code", has been found within a strict mode tree. String refs are a source of potential bugs and should be avoided. We recommend using useRef() or createRef() instead.
in pre (created by Highlight)
in Highlight (created by Learning)
in details (created by Learning)
in div (created by Learning)
in div (created by Learning)
in Learning (created by Layout)
in Route (created by Layout)
in Switch (created by Layout)
in Router (created by HashRouter)
in HashRouter (created by Layout)
in Layout
in StrictMode
我的理解是这是一个由 引起的警告react-highlight
,我能做些什么来删除它?
解决方案
推荐阅读
- go - 对多次组合的对象的类型断言
- excel - VBA将某些列复制到所有工作表
- prolog - Prolog 列表 - 重复的头部
- c - 如何将结构数组的属性作为参数发送给 C 中的函数?
- java - 当我准备好驱动程序类时,为“WAR”纸牌游戏创建一个类
- java - 例外:没有 Hibernate Session 绑定到线程,并且配置不允许在此处创建非事务性会话
- sql-server - 从 SQL Server 中的 XML 列中提取所有属性值
- javascript - javascript 中的 hasOwnProperty 和 Object.keys 无法按预期工作
- eclipse - Eclipse 中没有可用的源代码
- java - java - 如何在java中将两个二维数组相等?