- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我操纵组件的状态并使用状态中的对象(输入参数)来显示一些信息。
const renderTooltip = ({ object: hoveredObject, x: pointerX, y: pointerY }) => {
// console.log(hoveredObject);
const {points} = hoveredObject;
const calLoadTime = () => {
const rawTime = points.reduce(
(accumulator, currentValue) =>
currentValue ? accumulator + currentValue.SPACES : accumulator,
0
) / points.length;
return rawTime.toFixed(1);
}
return (
<span
style={{
lineHeight: '20px',
borderRadius: '3px',
width: '200px',
left: pointerX+10,
top: pointerY+5,
}}
>
{`Length: ${points.length}\n`}
</span>
)
}
但是收到以下警告,我检查了我没有操作 DOM 元素上的状态,或者有一些名为 viewState
的属性?这个警告是什么意思?
Warning: React does not recognize the
viewState
prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercaseviewstate
instead. If you accidentally passed it from a parent component, remove it from the DOM element.
我的组件的完整代码如下所示:
import React, { memo, useEffect, useRef, useState } from 'react';
import DeckGL, {HexagonLayer} from 'deck.gl';
import { StaticMap } from 'react-map-gl';
import { INITIAL_VIEW_STATE, LAYER_CONFIGS } from './configs';
import { addMapControl } from './tools';
import { MAPBOX_TOKEN } from './constants';
import styles from './index.less';
const Map = (props) => {
const {
controller = true,
baseMap = true,
initialViewState = INITIAL_VIEW_STATE,
layerType = '3d-heatmap',
renderTooltip = DEFAULT_RENDER_TOOLTIP,
} = props;
const [tooltip, setTooltip] = useState({
object: null,
// eslint-disable-next-line react/no-unused-state
x: 0,
// eslint-disable-next-line react/no-unused-state
y: 0,
})
/**
* layers render function
*/
const renderLayers = () => {
const {
data,
accData = [],
accSpeed = 0.1,
accRadiusScale = 4,
accRadiusMaxPixels = 200,
accColorRange,
coverage = 1,
radius,
elevationScale,
...otherProps
} = props;
const layers = [];
layers.push(
new HexagonLayer({
...LAYER_CONFIGS.AugmentHexagonLayer,
...otherProps,
coverage,
data,
radius,
onHover: setTooltip,
}),
);
return layers;
}
/**
* add Control for language switching
* @param {*} event
*/
const addControlHandler = (event) => {
const map = event && event.target;
if (map) {
addMapControl(map);
}
};
const { object } = tooltip || {};
return (
<DeckGL
width="100%"
height="100%"
layers={renderLayers()} // eslint-disable-line
initialViewState={initialViewState}
controller={controller}
>
{baseMap && (
<StaticMap
onLoad={addControlHandler}
reuseMaps
mapStyle="mapbox://styles/mapbox/dark-v9"
preventStyleDiffing
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
)}
{object && renderTooltip(tooltip)}
</DeckGL>
);
}
我使用了一些第三方包来使工具提示在 map 中显示。
renderTooltip
props 由输入 renderTooltip
分配我上面提到的函数,我使用 tooltip
状态来控制是否应该在页面中显示工具提示。
PS:根据deck.gl的文档,onHover
将在以下时间触发:
onHover (Function, optional)
This callback will be called when the mouse enters/leaves an object of this deck.gl layer with the following parameters:
info
event - the source event
根据错误跟踪路径,它在我的 <span>
中抛出错误元素,这就是为什么我认为它是 renderTooltip
首先是问题。
Warning: React does not recognize the `viewState` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `viewstate` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
in span (created by Map)
in div (created by DeckGL)
in div (created by DeckGL)
in DeckGL (created by Map)
in Map (created by SpatialTemporal)
in section (created by SpatialTemporal)
in SpatioMap
in section
in Unknown (created by LBS)
in div
in div
in Unknown (created by LBS)
in LBS (created by Connect(LBS))
in Connect(LBS) (created by DynamicComponent)
in DynamicComponent (created by Route)
in Route (created by BasicLayout)
in Switch (created by BasicLayout)
in div (created by BasicLayout)
in div (created by Basic)
in Basic (created by Adapter)
in Adapter (created by BasicLayout)
in div (created by BasicLayout)
in BasicLayout (created by Adapter)
in Adapter (created by BasicLayout)
in div (created by BasicLayout)
in BasicLayout (created by Adapter)
in Adapter (created by BasicLayout)
in div (created by ContainerQuery)
in ContainerQuery (created by BasicLayout)
in DocumentTitle (created by SideEffect(DocumentTitle))
in SideEffect(DocumentTitle) (created by BasicLayout)
in BasicLayout (created by Connect(BasicLayout))
in Connect(BasicLayout) (created by DynamicComponent)
in DynamicComponent (created by Route)
in Route (created by DvaRoot)
in Switch (created by DvaRoot)
in Router (created by DvaRoot)
in LocaleProvider (created by DvaRoot)
in Provider (created by DvaRoot)
in DvaRoot
最佳答案
我今天遇到了同样的问题,并通过不将工具提示添加为 DeckGL 的直接子项来解决它:
return (
<React.Fragment>
<DeckGL
width="100%"
height="100%"
layers={renderLayers()} // eslint-disable-line
initialViewState={initialViewState}
controller={controller}
>
{baseMap && (
<StaticMap
onLoad={addControlHandler}
reuseMaps
mapStyle="mapbox://styles/mapbox/dark-v9"
preventStyleDiffing
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
)}
</DeckGL>
{object && renderTooltip(tooltip)}
</React.Fragment>
);
关于javascript - 警告 : React does not recognize the `viewState` prop on a DOM element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54300172/
我在 Python(3.5 版)中尝试使用语音识别模块,但遇到了以下错误: 'AttributeError: 'Recognizer' object has no attribute 'recogni
我正在尝试编译 C++ 程序,但遇到一些问题。特别是,当我使用 x86_64-w64-mingw32-gcc 作为编译器时,它在编译过程中提示“tmp/src/libfastms/solver/sol
我正在尝试安装 R 的 plyr 包。这是错误消息: * installing *source* package ‘plyr’ ... ** package ‘plyr’ successfully u
我第一次尝试使用多个文件构建程序。只用 main.cpp 编译程序我从来没有遇到过任何问题。使用以下命令,结果如下: $ g++ -c src/CNumber.cpp src/CNumber.h -o
我正在努力通过 The Little Book About OS Development ,特别是关于帧缓冲区的部分(链接)。我能够成功地汇编、链接、转换成 ISO 文件并启动纯程序集,但是一旦我尝试
我有一个关于 Swift 中 UIPanGestureRecognizer 的奇怪案例。我有一个处理平移手势的函数,并在 UIGestureRecognizerDelegate 中指定“false”,
抱歉,标题太长了。 我正在尝试将我们的功能测试代码与我们的集成测试代码隔离开来,并使用 gradle 任务让它工作。它也有 95% 在 intellij 中工作,除了每次我做一个“gradle ide
我想编写一个软件,当 USB 拇指驱动器连接到 USB 端口时,它会自动将一些文件复制到 USB 拇指驱动器上。为此我想知道: 我如何编写一个 c++ 应用程序,在 USB 拇指驱动器连接时收到通知?
我现在正在使用 BACKTRACK 5,它几乎像 ubuntu,一个 debian 和它的 32 位,我安装了 nasm,我去看了 dr. paulcarter 的汇编语言教程并下载了他的示例程序 (
我正在尝试编译一个包含以下行的 makefile: gcc -I. -I/home/usr/Documents/MTV/include -ggdb3 -Wall -O2 -o ascii2bin.c
我去了Chocolatey website并复制安装文本并粘贴到管理员 cmd.exe(使用 Windows 7)。当我运行命令时,我得到: 'powershell' is not recognize
我目前正在使用 Eventstore,但收到以下错误:Could not recognize BadRequest; 来自: game process tick failed UnknownError
我正在使用 jquery-1.11.1,并尝试使用 :data 选择器,如上所述 https://api.jqueryui.com/data-selector/ 尝试查找具有特定键的所有元素,如下所示
我有一个滚动功能,我需要执行它来滚动到其容器中的最后一条消息,该容器是带有 chunk_id 的容器。问题是它按原样进入容器,但如果我将最后一个子添加到混合中,该功能将不起作用。有什么想法我做错了吗?
我正在使用 sphinx4 暂停线程,直到说出特定的关键字。第一次效果很好,但第二次我需要暂停线程, recognizer.recognize() 似乎没有运行,应用程序只是开始发送垃圾邮件“开始说话
我正在尝试检查我的应用程序是否被授予访问用户提醒的权限,方法是: EKEventStore *store = [[EKEventStore alloc] init]; EKAuthorizationS
我有一个 foo 对象,如下所示: var foo = { "timer" : { "hours" : 0, "minutes" : 0,
我正在尝试运行位于此处的代码: http://r3dux.org/2010/11/single-call-opengl-texture-loader-in-devil/ 而且它需要我使用 DevIL,
我交叉编译了arm的内核源代码,带有调试信息和KGDB。 当我在主机中运行 gdb 时: $ arm-linux-gnueabihf-gdb vmlinux ... Reading symbols f
我使用 pip 将 virtualenv 安装到我的项目目录中。但是,当我在 Windows 终端中运行命令 virtualenv venv 时,它只是告诉我它无法识别。 我必须在 Python 中做
我是一名优秀的程序员,十分优秀!