-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Is lodash really necessary in 'Creating tags pages for blog posts'? #4078
Comments
No, lodash is not necessary. It's a utility library which makes a lot of things simple. In this case, your code should just work fine without lodash (unless I'm overseeing something). Perhaps you need some error handling I guess, say if a |
@CrowsVeldt It's a good question! I don't think lodash is absolutely necessary in this case. However it's slightly safer than the no lodash (nodash?) example. The e.g. if your edge has no frontmatter at all: const edge = { node: {} }
if (edge.node.frontmatter.tags) {
// do some things here
}
// The above code will throw an error like:
// Uncaught TypeError: Cannot read property 'tags' of undefined
// at <anonymous>:1:27
// Here, get() just returns undefined and carries on
if (_.get(edge, 'node.frontmatter.tags')) {
// do some things here
} Generally I agree we should be keeping things as 'standard' as possible, particularly in the docs. What do other folks think about removing lodash from this example? |
That makes sense, thanks! I think it stands out in particular because the rest of the docs don't use lodash, and then it's used here without an explanation as to what value it provides. I also think keeping the docs standard is good. I think at least there should be a note along the lines of:
I could try to make a PR to that effect. What do you think? |
Hmm yeah — if we're using lodash, we should show importing individual functions. Importing the whole library adds quite a bit of weight. And if we can easily avoid it we should. |
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help! |
Creating this comments for anyone else that has search for this answer: You can install lodash.isequal as a single module without installing the whole lodash package like so:
Then initializing const kebabCase = require('lodash.kebabcase')
...
{`/tags/${kebabCase(tag)}`} Should we update the docs, @KyleAMathews? I can make a PR. https://www.gatsbyjs.org/docs/adding-tags-and-categories-to-blog-posts/#modify-gatsby-nodejs-to-render-pages-using-that-template Before: After: |
I added a tags page to my site following Creating tags pages for blog posts and I'm wondering about the use of lodash. I am still new at programming so there may be a reason it is necessary that I'm unaware of, but if that is the case wouldn't be better to mention it in the article?
I removed it from my site, just to make sure it is possible, and it hasn't caused any problems so far.
For example in place of the following:
I have this:
I spent a few hours checking the commit history, issues, and PRs, and didn't find any discussion of this. Please let me know if this is out of place or anything.
The text was updated successfully, but these errors were encountered: