why-did-you-render icon indicating copy to clipboard operation
why-did-you-render copied to clipboard

Can you provide a Next.js v12 example?

Open dungle-scrubs opened this issue 2 years ago • 4 comments

I've been trying to get it to work with Next.js v11 and now v12 but have never had any success. Would you mind providing an example?

Thanks

dungle-scrubs avatar Apr 04 '22 02:04 dungle-scrubs

@dungle-scrubs Hello, i use next v12.

You need the steps as follows :

1. Create a wdyr.js

import React from 'react';
if (process.env.NODE_ENV === 'development') {
    const whyDidYouRender = require('@welldone-software/why-did-you-render');
    whyDidYouRender(React, {
        trackAllPureComponents: true,
        onlyLogs: true,
        titleColor: "green",
    });
}

2. Import the wdyr.js in _app.js

import '../hooks/wdyr';

3. Add props in the compostant


const XXX=()=>{
    return <h1>xxx</h1>
}
XXX.whyDidYouRender = true;
export default XXX;

qfdk avatar Jun 30 '22 09:06 qfdk

@qfdk Thank you, that helped.

dungle-scrubs avatar Jul 05 '22 07:07 dungle-scrubs

For me it didn't worked untlll I added

"jsxImportSource": "@welldone-software/why-did-you-render"

to tsconfig.ts

apperside avatar Dec 12 '22 15:12 apperside

@apperside Thanks. Can confirm this was also the solution to allow wdyr logging for Next 13.

mikechabot avatar Jan 09 '23 01:01 mikechabot