Giter Site home page Giter Site logo

Comments (10)

piotrkochan avatar piotrkochan commented on May 10, 2024 41

I've added some myComp.whyDidYouRender = true but still there is no logs

from why-did-you-render.

vzaidman avatar vzaidman commented on May 10, 2024 4

copied from the readme:

https://github.com/welldone-software/why-did-you-render#usage

mark all the components you want to be notified about their re-renders with whyDidYouRender like so:

class BigListPureComponent extends React.PureComponent {
  static whyDidYouRender = true
  render(){
    return (
      //some heavy render you want to ensure doesn't happen if its not neceserry
    )
  }
}

Or like this:

const BigListPureComponent = props => (
  <div>
    //some heavy component you want to ensure doesn't happen if its not neceserry
  </div>
)
BigListPureComponent.whyDidYouRender = true

Or track all the components that are matched by their name in the include array like this:

if (process.env.NODE_ENV !== 'production') {
  const whyDidYouRender = require('@welldone-software/why-did-you-render');
  whyDidYouRender(React, { include: [/^pure/], exclude: [/^Connect/] });
}

You probably don't want the regex way since it will find many many re-renders.

Better focus on your bigger bottleneck components using the first way.

from why-did-you-render.

StuartFlutter avatar StuartFlutter commented on May 10, 2024 2

I just tried to use whyDidYouRender, have installed it correctly and followed instructions exactly, and still see no logged output of any kind

from why-did-you-render.

EstebanBP avatar EstebanBP commented on May 10, 2024

My bad, I should have read better.
Thanks!

from why-did-you-render.

vzaidman avatar vzaidman commented on May 10, 2024

how do you use "myComp"? (by the way it sohuld probably be capital letter: "MyComp"

from why-did-you-render.

rbrewington avatar rbrewington commented on May 10, 2024

I also can't seem to see any logs. Is this some issue with functional components?

Edit: After a bit of further research, it seems to work on some components. Is it not possible to get logs on components that are conditionally rendered?

from why-did-you-render.

vzaidman avatar vzaidman commented on May 10, 2024

try the example here:
#14 (comment)

there are only logs if renders can be prevented.

from why-did-you-render.

vzaidman avatar vzaidman commented on May 10, 2024
  whyDidYouRender(React, {
    trackAllPureComponents: true,
  });

would track all pure components. does it answer your question?
what do you mean by "conditionally rendered"?

from why-did-you-render.

rbrewington avatar rbrewington commented on May 10, 2024

I made an issue specific to my use case: #94

By conditionally rendered, I mean it's only rendered under certain conditions. Suppose you have a boolean isLoading.
And your component returns either a loading indicator or the content depending on if isLoading is true. The content is conditionally rendered in this case.

from why-did-you-render.

dimashpt avatar dimashpt commented on May 10, 2024

React native has different development flag than react for web
Just change your condition from
if(process.env.NODE_ENV !== 'production')
to:
if (__DEV__)

And viola

from why-did-you-render.

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.