Giter VIP home page Giter VIP logo

Comments (6)

sainer avatar sainer commented on June 12, 2024 1

Yes. It's perfect solution. Thanks for help. I changed my code and it works fine

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

Wouldn't relying on the loading flag allow you to carry out this logic?

from axios-hooks.

sainer avatar sainer commented on June 12, 2024

It depends on when loading flag is set to false. Currently I'm using useState and my own state flag to check is component rendering after successful request. I do it in if clause. I'm checking response.status and if it's as 200 code then I'm setting this flag to true. Initially this flag is also true, and it's set to false only if the app manually execute HTTP request (axios manual method) - I do it after user click the button to send provided data to API.

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

Can you provide an example? Explaining code in words is not easy to follow.

from axios-hooks.

sainer avatar sainer commented on June 12, 2024

This is my actual sample code

.......
  const [requstFinished, setReqestFinished] = useState(false);
  const tickerInput = props.channel.ticker_text
  const [ticker, setTicker] = useState();
  useEffect(() => {
      setTicker(props.channel.ticker_text);
  }, [props.channel.ticker_text])
  const [ { response: putResponse, loading: putLoading, error: putError }, executePut ] = useAxios(
    {
      url: ROOT_BACKEND_URL + "channels/" + props.channel.id,
      method: "PUT",
      headers: HTTP_HEADERS
    },
    { manual: true }
  );
  const handleRequestSave = () => {
    executePut({ data: JSON.stringify({ tickerText: ticker }) });
    setReqestFinished(false)
  };
  if (putLoading)
 ///here I have a spinner
  if (putError) {
    if (putError.response) toast(putError.response.status, { type: "error" });
    else toast("Error", { type: "error" });
  }
  if (putResponse && !requstFinished) {
    if (putResponse.status==200) {
      toast("Success", { type: "success" });
      setReqestFinished(true)
    }
  }
return(
...........

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

executePut will return a promise that will tell you when the request has completed. will that help?

from axios-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.