0

I’m fetching data from GitHub API and I have a search and submit button. So basically after each user search I want to store the search name to another page that I have built. That is how I am getting the data:

const handleSubmit = (e: React.MouseEvent<HTMLElement>) => {
    axios
      .get(`https://api.github.com/users/${inputText}/repos`)
      .then((response) => {
        setData(response.data);
      })
      .catch((error) => {
        console.log('error', error);
      })
  };

inputText is basically what I want to store or the e.target.value otherwise from search component?

What is the best way to approach it? Use local storage somehow or React useContext?

Any help would be appreciated!

kukri
  • 93
  • 1
  • 8
  • Does this answer your question? [Persist variables between page loads](https://stackoverflow.com/questions/29986657/persist-variables-between-page-loads) – Andy Ray Sep 16 '22 at 23:18
  • 1
    I think [this answer](https://stackoverflow.com/a/62106152/19826504) will provide you more information about context/localStorage and when to choose what. so basically you can save the data both ways, but it depends on what are you trying to achieve. – Yarin Barnes Sep 17 '22 at 00:55

0 Answers0