The react-router passes the parameters, and the parent component passes the parameters to the child page, which is executed twice.

react-router version
"react-router": "^ 3.0.0",
"react": "^ 15.5.4",

routing configuration
< Route path= "/ imglivedetial/:mid/:type" component= {ImageLiveDetial} / >

because parameters are entered directly in the address bar, props.parmars, is not updated, so a custom refresh props function refreshProp () is executed in both componentWillReceiveProps and componentDidMount

refreshProp () makes api requests or refreshes status. But twice every time.

solve

Apr.03,2021

isn't that obvious? You can make a breakpoint in refreshProp and take a look at the stack.

the following is my guess that is not based on facts:

execute componentDidMount, once when the page is mounted to execute refreshProp

the page update phase (props change) executes componentWillReceiveProps, once to execute refreshProp.

if you want to execute it once, why not delete the refreshProp in componentWillReceiveProps.


generally speaking, my own writing is not rigorous, which can be regarded as a curve to save the nation. Change componentWillReceiveProps () to

.
  componentWillReceiveProps(nextprops){
    let refresh = false;
    Object.keys(nextprops).forEach((value, index) => {
      if(nextprops[value] != this.props[value]){
        refresh = true;
      }
    })
    if(!refresh) return;
    this.refreshProps(nextprops);
  }

first determine whether the nextprops has changed in componentWillReceiveProps, and then refresh the component. This temporarily solves the problem of multiple (more than two) ajax requests. If there are several prop parameters, componentWillReceiveProps will execute it several times.

then split the ajax request into separate functions to determine whether the required ajax parameter is empty, and if it is empty, it will not be executed, thus solving the problem of two ajax requests (if the request parameter is not strict, the request is also sent if it is empty. )

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e95f-2c431.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e95f-2c431.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?