开发者问题收集
我想知道如何在第一次重新加载页面时获取 api,然后每小时再次调用 api 一次来更新我的 UI,因为该 api 默认每小时更新一次这是我的代码const [news, setNews] = useState([])useEffect(() => {setInterval(() => {(async () => {tryÏ {const res = await fetch(`https://new
我是 React 新手,遇到了如下问题:Uncaught TypeError: Cannot read property 'setState' of null.基本上,我想做的是,用户可以点击三个不同的标题,点击后,它将呈现特定于该标题的特定模板。这是我当前使用的代码,它给了我这个错误:class Selection extends React.Component {constructor(pro
我的问题是,当我尝试在输入框中写入某些内容时,会出现此错误。有人能帮助我吗?谢谢(顺便说一下,我是 React 新手)class Searcher extends Component {constructor(props) {super(props)this.state = {inputValue: ''}}onChange (e) {console.log(e)this.setState({in
我试图在函数内部设置 React 中的状态,但是我收到一条错误消息,指出:无法读取未定义的属性“setState”。下面是我的代码,我在构造函数中调用状态,然后在 addTimes 函数中设置状态并将其绑定到该函数,但是我仍然收到错误。class Settings extends React.Component {constructor(props) {super(props);this.stat
为什么 onMapClicked 可以工作,但 onGpsClicked 不工作 this.setState显示错误 TypeError:无法读取未定义反应的属性“setState”.............................................................................................................
我从 Firebase 实时数据库获取了一些数据,现在我正尝试将其添加到变量中。我确信查询有效,因为如果我 console.log(dataSnapshot),它会记录正确的数据(即 001)。但是,当我尝试使用该数字创建变量时,我收到以下错误:无法读取未定义的属性“setState”,并且它不会向控制台返回任何内容。这是我的代码:class Table extends Component {co
为什么我会遇到此错误?未处理的拒绝(TypeError):无法读取未定义的属性(读取“setState”)?这是因为 addDepartment 中没有检测到它它无法理解这是 CustomToolbar 组件?请帮忙。class CustomToolbar extends React.Component {//constructor(props) {super(props)this.HandleA
我有一个 React 代码此代码在 UI 中呈现各种面板。当我单击标签时,此函数称为 sportsCornerPanel()但我得到了 Uncaught TypeError,如何修复它提供以下代码片段。您可以在 fiddle 中看到整个代码代码片段 sportsCornerPanel() {debugger;console.log("sportsCornerPanel"console.log
我在渲染函数中调用 this.getAllJobsAPI();。这成功调用了 getAllJobsAPI(如下所示),并且我能够从作业的 JSON 数组中检索作业名称。getAllJobsAPI(){var headers = new Headers();headers.append('Authorization', 'Basic YWRtaW46YWRtaW4=');fetch('http://
我一直在关注 Tyler Mcginnis 的教程,但在使用 React Router 时遇到了问题,特别是历史记录。我最终逐字逐句地复制了他的代码,只是为了看看是不是只有我一个人遇到这个问题,但我仍然得到Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a
当 /logout 路由被点击时,我尝试将用户重定向到登录页面。身份验证正在运行(jwt 令牌已被删除,但应用程序无法重定向到 /login。此外,如果我对 / 执行此操作,应用程序也会崩溃。在登录路由上,我使用 react-router-dom 包中的 withRouter,这样我可以访问this.props.history.push('/redirect_to_a_new_path'),但是当
因此,我尝试在 React 中使用history,但它似乎被移动了很多次。我发现了这一点:https://github.com/ReactTraining/react-router/blob/ab4552d2ea0ec5c0cf3c534bca654a1af3ea0dec/docs/guides/NavigatingOutsideOfComponents.md但它只是说'react-router'
有人可以帮助我,我想使用 React Router,但是我有一个无法修复的错误。我的错误是:“react-router”不包含名为“browserHistory”的导出。我的代码如下谢谢 ^^import React, { Component } from 'react'import {Router, Route, Link,browserHistory,IndexRoute} from 'rea
App.tsx部分代码:interface AppProps{history: any}export default class App extends React.Component<AppProps,...> {public state = {target: this.props.history.push('/')};private route() {if (!session.isLogin)
我使用npx create-react-app app-name创建了一个新的 React 应用程序。然后我将目录更改为该应用程序文件夹,然后运行以下命令。npm install react-router@next react-router-dom@next然后我运行我的应用程序,它运行良好。然后我更改了默认代码并使用了 Routes、Route 等。这是 APP 代码import React f