Skip to content

Commit

Permalink
eliminated forward ref warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaidman committed Dec 29, 2024
1 parent 8cbb1c1 commit 7eed9c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import strict from './strict';
import reactRedux from './reactRedux';
import styledComponents from './styledComponents';
import logOwnerReasons from './logOwnerReasons';
import forwardRef from './forwardRef';

const demosList = {
bigList,
Expand All @@ -47,6 +48,7 @@ const demosList = {
reactReduxHOC,
styledComponents,
logOwnerReasons,
forwardRef,
};

const defaultDemoName = 'bigList';
Expand Down
30 changes: 30 additions & 0 deletions demo/src/forwardRef/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';

export default {
description: 'forwardRef',
fn({reactDomRoot, whyDidYouRender}) {
whyDidYouRender(React);

const Main = React.forwardRef((props, ref) => {
return <div ref={ref}>hi</div>;
});

Main.whyDidYouRender = true;

Main.displayName = 'Main';

const App = () => {
const [,setState] = React.useState(0);

React.useLayoutEffect(() => {
setState(s => s + 1);
}, []);

return <Main a={[]}/>;
};

App.displayName = 'App';

reactDomRoot.render(<App/>);
},
};
1 change: 0 additions & 1 deletion jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const substringsToIgnore = [
'Selectors that return the entire state are almost certainly a mistake',
'Warning: ReactDOM.render is no longer supported in React 19',
'Support for defaultProps will be removed from',
'forwardRef render functions accept exactly two parameters'
];
const regexToIgnore = new RegExp(`(${substringsToIgnore.join('|')})`);

Expand Down
4 changes: 2 additions & 2 deletions src/patches/patchFunctionalOrStrComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function patchFunctionalOrStrComponent(FunctionalOrStringComponen
getFunctionalComponentFromStringComponent(FunctionalOrStringComponent) :
FunctionalOrStringComponent;

function WDYRFunctionalComponent(nextProps, ...args) {
function WDYRFunctionalComponent(nextProps, refMaybe, ...args) {
const prevPropsRef = wdyrStore.React.useRef();
const prevProps = prevPropsRef.current;
prevPropsRef.current = nextProps;
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function patchFunctionalOrStrComponent(FunctionalOrStringComponen
}
}

return FunctionalComponent(nextProps, ...args);
return FunctionalComponent(nextProps, refMaybe, ...args);
}

try {
Expand Down

0 comments on commit 7eed9c5

Please sign in to comment.