Skip to content
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

Get extractedGitHubUrls to work with conditional rendering #2378

Closed
humphd opened this issue Oct 21, 2021 · 3 comments
Closed

Get extractedGitHubUrls to work with conditional rendering #2378

humphd opened this issue Oct 21, 2021 · 3 comments
Labels
area: performance Issues related to our performance type: enhancement New feature or request

Comments

@humphd
Copy link
Contributor

humphd commented Oct 21, 2021

In #2367 we're adding GitHub info for posts, and we have included a new function, extractedGitHubUrls. We'd like to memoize this result, but our early work at doing so hasn't been successful. Here's what we think it should look like, but it needs to get fixed so it works:

  // Extract all the github urls from the post
  const extractedGitHubUrls: string[] = useMemo(
    () => (post?.html ? extractGitHubUrlsFromPost(post.html) : []),
    [post?.html]
  );
  ...
  {extractedGitHubUrls.length ? <GitHubInfo ghUrls={extractedGitHubUrls} /> : null}

cc @menghif @DukeManh

@humphd humphd added type: enhancement New feature or request area: performance Issues related to our performance labels Oct 21, 2021
@menghif
Copy link
Contributor

menghif commented Oct 21, 2021

It currently works with useMemo as of right now. However it does not work if we change this:

{extractedGitHubUrls.length ? <GitHubInfo ghUrls={extractedGitHubUrls} /> : null}

into this:

{extractedGitHubUrls.length > 0 ?? <GitHubInfo ghUrls={extractedGitHubUrls} />}

We have used this syntax: condition && <Component/> in GitHubInfo.tsx so we would like to change it here too for consistency.

@humphd humphd changed the title Memoize extractedGitHubUrls Get extractedGitHubUrls to work with conditional rendering Oct 21, 2021
@menghif
Copy link
Contributor

menghif commented Oct 21, 2021

@humphd We can delete this, I fixed it in #2367. It was a typo ?? instead of &&. Sorry about that.

@humphd
Copy link
Contributor Author

humphd commented Oct 21, 2021

Awesome!

@humphd humphd closed this as completed Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: performance Issues related to our performance type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants