-
Notifications
You must be signed in to change notification settings - Fork 1.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
Added tutorial for using Prism.js with React #1979
Conversation
That you for creating the tutorial! @mAAdhaTTah Could you please review it? I'm not familiar with the Babel plugin. |
Changed the domain of my blog where the tutorial was hosted, old URL is 301 forwarded incase
Reading over the tutorial now. I love having this on the site, but have a few comments for OP:
This shouldn't be the case if
I'd actually suggest, for usage with React, using the Also, the use of curly quotes in the code snippets is breaking highlighting, I think, and will def not work for people who want to copy the snippet. The babel plugin configuration is super helpful though, thank you for including that! I know the docs for the babel plugin are a bit meh, and we've got a few bugs / issues to iron out. That said, I'd still merge this. |
@mAAdhaTTah , thank you very much for your thoughtful suggestions. I will make the necessary changes to the tutorial and post here when it's updated. |
@mAAdhaTTah, I've reviewed the tutorial and made the following changes.
Thanks again for taking the time to read and giving feedback. @RunDevelopment, thanks as well for considering the tutorial |
I'm not a React developer, but using highlight = () => {
if (this.ref && this.ref.current) {
Prism.highlightElement(this.ref.current)
}
} |
An arrow function as I wrote ensures that the function is bound to the component. Meaning no matter the context in which the function is executed, For example, if I wrote that function normally like
Then say I tried to do this
The highlight function would run but there would be no
As such, using the arrow function syntax avoids needing to do that and is a bit of a shortcut. It just ensures that |
It does! Thanks for the explanation. I just learned something new. |
Looks good! One minor nit:
|
Hey guys, thought this would be helpful to write. I love Prism but always felt a bit lost trying to use it with React. Hopefully this helps others in a similar position.