我是个新手,我得到了以下错误:
react-dom.development.js:14906 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might
我有一个组件,它使用另一个组件作为呈现器。但是,React不允许我在呈现器组件中使用钩子,因为它会引发以下错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
下面是显示组件中的一个示例,它是一个错误边界
class DisplayComponent extends Component {
// ...
render() {
const { rendererComponent } = this.props;
return re
我想从一个组件到另一个组件访问状态。为此,我只想将contextprovider包装到单击按钮时状态发生变化的组件,并从usehook返回状态,以便另一个组件可以访问该状态。
下面是组件在未应用上下文的情况下的外观,
function Parent () {
return (
<UploadButton/>
);
}
function UploadButton () { //this is where state is set
const [isDialogOpen, setIsDialogOpen] = React.useState(fa
我正在试图弄清楚解除国家是如何运作的。目前,我正尝试在另一个组件中使用onPress来更改状态。在我下面提供的小吃演示中,ListHome和MapHome由于某些原因没有响应,但是您仍然会看到我正在尝试完成的任务。
我想要地图和列表“按钮”来完成“点击这个”所做的工作。
-没有错误的当前实现,只是没有反应,除了闪光灯从可触摸的不透明度。(也要记住,由于某种原因,零食没有反应。我的本地设备工作正常)
编辑:为了清楚起见,我希望能够从另一个组件访问和更改状态whichComponentToShow。即ListHome组件。
export default class Home extends Re
如何使用一个变量来存储来自mongoDB的数据,在另一个react组件中,我们可以使用从mongoDB获取并存储在该变量中的数据。
获取来自mongoDB的数据并将其存储在名为 data 的变量中的文件代码
import React,{useEffect,useState} from 'react'
import './HeroSection.css'
import axios from 'axios'
import {useHistory} from 'react-router-dom';
function Homefilte