Skip to content

[Basic] Provide some docs on memo #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
silverwind opened this issue Jun 26, 2024 · 6 comments
Closed

[Basic] Provide some docs on memo #719

silverwind opened this issue Jun 26, 2024 · 6 comments
Labels
BASIC Basic Cheatsheet

Comments

@silverwind
Copy link

silverwind commented Jun 26, 2024

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/>;
});
@silverwind silverwind added the BASIC Basic Cheatsheet label Jun 26, 2024
@silverwind silverwind changed the title [Basic] ISSUE_TITLE_HERE [Basic] Provide some docs on memo Jun 26, 2024
@filiptammergard
Copy link
Collaborator

Sounds like it could be useful. Feel free to contribute!

@UdaySharmaGitHub
Copy link

Assign me this issues

@filiptammergard
Copy link
Collaborator

Assign me this issues

Just create a PR if you want to contribute

@UdaySharmaGitHub
Copy link

@filiptammergard i just contributed the Memo and Memoization in React with TypeScript. and raised the PR.

@ripu2
Copy link

ripu2 commented Oct 1, 2024

@filiptammergard I've raised the PR, please do check

@filiptammergard
Copy link
Collaborator

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!

@filiptammergard filiptammergard closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BASIC Basic Cheatsheet
Projects
None yet
Development

No branches or pull requests

4 participants