我已经探索了整个网络的解决方案,但没有任何工作对我的期望。我的Api被调用了两次,导致数据库中的数据重复。我要他们只触发一次。
请查找以下代码:
<Route
path="/apis/wallet_verification"
render={(routerProps) => {
//deals with some params
console.log("I am triggering");
axios.get(`http://website/apis/
新的反应/下一步,抱歉,如果这是显而易见的,我试着寻找并尝试解决类似的问题,但我认为我遗漏了一些东西或没有正确理解。我知道loadStats()被无限调用,因为它是在呈现函数中调用的,我只是不知道如何解决它.
我试过onClick={loadStats(stats.player).bind(stats.player)}它只是错误bind() is not a function..。这是组件。
import React, { useEffect, useState } from "react";
import Teams from "./Teams";
cons
我有一个用于管理身份验证的privateRoute组件:
const PrivateRoute = ({ component: Component, auth, ...rest }) => {
// This gets logged twice when I navigate in the app
// Using history.push("/url")
// And gets logged once when I type the url and hit enter on the browser
console.log(
"======
这就是我们使用componentWillReceiveProps的方式
componentWillReceiveProps(nextProps) {
if(nextProps.myProp !== this.props.myProps) {
// nextProps.myProp has a different value than our current prop
}
}
它非常类似于componentDidUpdate
componentDidUpdate(prevProps) {
if(prevProps.myProps !== this.props.myProp)
我正在尝试将一个UserId发布到数据库,但是Id被作为一个支柱传递。当我在render方法中输入this.props.userId时,它会显示所需的信息,但是当我试图将它合并到呈现函数之上的函数中时,就会得到null。我花了好几个小时查看其他帖子,尽我所能去试一试,但都没有用。
App.js码
import axios from 'axios'
import {
BrowserRouter as Router,
Route,
Redirect,
} from 'react-router-dom'
import Home from "./pa