I am working on project , where I am updating the url . Actually It working fine when I click on next button but I want to re-render application when function is invoked . I am new to ReactJS , Could some one please help me how to solve this problem .
I am sorry I am not native speaker , I am sorry if I made mistake in English grammer . Thanks
Displaying data through this URL Function
urlParams() {
return `http://localhost:3001/meetups?filter[limit]=${(this.state.Item)}&&
filter[skip]=${this.state.skip}
&&filter[order]=${this.state.sortedData}`;
}
Full Component Code
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
Item: 5,
skip: 0
}
this.handleClick = this.handleClick.bind(this);
}
urlParams() {
return `http://localhost:3001/meetups?filter[limit]=${(this.state.Item)}&&filter[skip]=${this.state.skip}`
}
handleClick() {
this.setState({skip: this.state.skip + 1})
}
render() {
return (
<div>
<a href={this.urlParams()}>Example link</a>
<pre>{this.urlParams()}</pre>
<button onClick={this.handleClick}>Change link</button>
</div>
)
}
}
ReactDOM.render(<Example/>, document.querySelector('div#my-example' ))
You can force a rerender of your component by calling:
this.forceUpdate();
However, you have to be careful not to enter a never-ending update cycle.
The usual (recommended) way to rerender is through the necessity of changing your state using setState
.
EDIT
I think want you need is to call getData once you have clicked the table header:
getSortedData=()=>{
console.log("hello clicked")
this.setState({
sortedData:'companyName'
})
// now invoke getdata which will refresh the data:
this.getData()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.