Skip to content
Advertisement

What do I do to use the function repeatedly in different components?

I’ve user object in local storage. I stored token and token date here User object like that;

  user: [{
     nickname,
     token,
     tokenDate,
  }}

I parse JSON and get data then sending header with Axios. But i don’t want to be code repetition. How do i that?

I hear react-component-lib is it right to use this? And last thing i don’t know Redux. So don’t be found in redux solutions.

Advertisement

Answer

For this particular case: you can add a header to all the requests with axios.interceptors.

And generally: you can always define and export your function, then just import it several times… not sure if that’s what you asked for.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement