GithubHelp home page GithubHelp logo

Comments (3)

philipwalton avatar philipwalton commented on August 20, 2024 2

@hindsc52

Is this the correct way to call these methods? The component this is in is called in the main layout container that is used to wrap each page.

I'm not super familiar with React hooks, but yes, I believe useEffect() is the recommended way to prevent something from being executed on the server.

Another option would be to use dynamic import() to load the web-vitals library, which should also prevent that code from running when rendered on the server. Another advantage of using dynamic import() is it'll keep all the web-vitals code out of your app's main entry bundle.

@danoc

I'm also curious about this. Does it make sense to wrap the calls in a requestIdleCallback?

You do not need to use requestIdleCallback() with the web-vitals library. The underlying APIs themselves already do their best to dispatch the PerformanceObserver callbacks during idle periods, and in cases where that's not possible you need the callbacks to run right away (like if the page is unloading).

If you just use the callbacks as described in the docs, it shouldn't have any negative effects on performance.

from web-vitals.

danoc avatar danoc commented on August 20, 2024

I'm also curious about this. Does it make sense to wrap the calls in a requestIdleCallback?

https://developers.google.com/web/updates/2015/08/using-requestidlecallback#using_requestidlecallback_for_sending_analytics_data

from web-vitals.

sallf avatar sallf commented on August 20, 2024

I'm not super familiar with React hooks, but yes, I believe useEffect() is the recommended way to prevent something from being executed on the server.

This is an old post, but in case anyone else stumbles across it, I think it's worth noting that if you put these in a useEffect they should only be called ONCE on mount. See this discussion for more context:

#55 (comment)

from web-vitals.

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.