Giter Club home page Giter Club logo

Comments (5)

MuzafferDede avatar MuzafferDede commented on June 9, 2024 4

@maximelebastard I figured out, It is because of React 18's strict mode. If you turn off, it will be fine or you can rollback to React 17 until this is handled by use-http package. Some other packages also faced this.

from use-http.

MuzafferDede avatar MuzafferDede commented on June 9, 2024

+1

@maximelebastard Did you figure out anything?

from use-http.

maximelebastard avatar maximelebastard commented on June 9, 2024

@MuzafferDede Nope sorry, I ended up switching to axios-hooks
https://www.npmjs.com/package/axios-hooks

from use-http.

krishnasaga avatar krishnasaga commented on June 9, 2024

It is happening due to abort on unmount feature useEffect(() => request.abort, []) at

useEffect(() => request.abort, [])

If I remove this line it is working, but it is making duplicate get requests as component mounts, unmounts and remounts again in React 18 StrictMode.

Now I'm trying to solve this problem with abort the requests on unmount and making it work in React StrictMode.

Please let me know if you have any inputs

@alex-cory

from use-http.

vicmortelmans avatar vicmortelmans commented on June 9, 2024

I suppose this is the same issue that I see here.

An extract from my functional component:

    const [date, setDate] = useState(formatDate(nextDate(0), 'yyyy-MM-dd'))  // next Sunday
    const [jsonData, setJsonData] = useState({});

    // initializing Http API for fetching data from database
    const {loading, error, data} = useFetch(
        `https://${window.location.hostname}${proxy}/query?date=${date}`, 
        {responseType: 'json'}, 
        [date]
    );
    useEffect(() => {
        if (data) {
            setJsonData(data)
        }
    }, [data])

So I want to execute the effect when data becomes available. UseFetch is run when the component mounts, I can see the response coming back in the console, but the effect is not running. When I do setDate(), useFetch runs again on the new url, and then the effect is executed correctly!

Best regards,
Vic

from use-http.

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.