In React router, I have attributes before and onClick , as shown below
<li key={i}><Link to="/about" onClick={() => props.selectName(name)}>{name}</Link></li> state = { selectedName: '' }; selectName = (name) => { setTimeout(function(){this.setState({selectedName:name});}.bind(this),1000); // this.setState({selectedName: name}); }
When I provide a function with the timeout enabled by a click, its transition to a new page and after some state is updated, which leads to the display of the previous name until the state is updated with the new name.
Is there a way that it will move along the new route only after the code has been launched in the onClick function.
[]. (https://github.com/pushkalb123/basic-react-router/blob/master/src/App.js)
: Link history.push . Link onClick li. onClick history.push, , .
Link
history.push
onClick
li
setState callback, , .
setState
:
<li key={i} onClick={() => props.selectName(name)}> {name} </li> selectName = (name) => { this.setState({ selectedName:name }, () => { this.props.history.push('about'); }); }
, URL Params, , . , , / , /about/tom /about/pushkal. , , - URL- index.js:
<Route path="/about/:name" component={AboutPage}>
, about, :
<Link to={"/about/" + name}>{name}</Link>
, AboutPage, param this.props.params.name. .
this.props.params.name
, ,
Source: https://habr.com/ru/post/1692292/More articles:how does the initialValue function work in a javascript reduction function? - javascriptHow to compare two arrays of objects? - arraysJava: поиск элементов по индексу другого элемента - javaGet one (last) value from infuxdb - jsonArray sorting in ASC order depending on two key values? - sortingWhy is NodeJS inaccurate with the addition of a large number? - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1692294/react-react-router-dom-pass-props-to-component&usg=ALkJrhh1dIhWtXMv27Y_mXDmmYwyV9YQHQGulp: enclose a gulp-tabular result in an unnamed function - javascripthow to configure JavaMelody to monitor Jdbc connections in C3p0 DataSource - javaHow to relax api-call Microsoft Bot - restAll Articles