react
react copied to clipboard
[Basic] Provide some docs on `memo`
What cheatsheet is this about? (if applicable)
Basic cheatsheet
What's your issue or idea?
Some docs on memo would be useful.
For example it took me a while to understand that such a combination of memo and forwardRef is wrong (the resulting type would not include ref):
const Div = memo<Props>(forwardRef<HTMLDivElement, Props>(function Div(props, ref) => {
return <div ref={ref}/>;
}));
The correct way is to omit <Props> on memo if there is forwardRef inside it, so my suggestions are:
const Div = memo(forwardRef<HTMLDivElement, Props>(function Div((props, ref) => {
return <div ref={ref}/>;
}));
const Div = memo<Props>(function Div(props => {
return <div/>;
});
Sounds like it could be useful. Feel free to contribute!
Assign me this issues
Assign me this issues
Just create a PR if you want to contribute
@filiptammergard i just contributed the Memo and Memoization in React with TypeScript. and raised the PR.
@filiptammergard I've raised the PR, please do check
I realize that React.memo is not specific to React+TypeScript, so it's better to just look in the official React docs. In this project we only document things that are directly related to how to use TypeScript with React. Thanks for suggestion though!