1 year ago

#74158

test-img

mohit gupta

How to prevent api call when back button is clicked in react?

Will localStorage help me to go back the previous route without calling the api. Can anyone suggest me with an example?

In content.js

componentDidMount = () => {
    localStorage.setItem("state", JSON.stringify(this.state))
  }

In alert.js

goToAlert = () => {
  localStorage.getItem("state");
  this.props.history.push("/content");
}
    <div
       onClick={this.goToAlert}
    >
     <img
      src={BackArrowButton}
      alt="back-arrow"
    />
    </div>

reactjs

react-hooks

local-storage

0 Answers

Your Answer

Accepted video resources