Docs
Language
JavaScript

Methods

All of these achieve the same thing.

const o = {
  fn: function () {
      // do something
  }
}
 
const o = {
  fn: () => {
      // do something
  }
}
 
const o = {
  fn () {
      // do something
  }
}
 
// run - do something
o.fn

Base of Full Pathname

const path = require('path')
const file = '/home/user/dir/file.txt'
 
path.parse(file).base // file.txt
path.basename(file) // file.txt

React

Variable New Lines Omitted

There are times when you have a variable with new lines. When you display this variable <span>{someText}</span> normally. The result is as if those \ns didn't even exist. The solution is simple. Just stick this in the css of the text.

style={{ whiteSpace: 'pre-wrap' }}

Unsupported Attributes

Including attribute with empty quotes does the trick1.

<input directory="" webkitdirectory="" type="file" />

Next x Prisma

If you're encountering an issue where your Prisma client is not working inside the getServerSideProps function while using Next.js with Prisma, and you receive the error message "PrismaClient is unable to be run in the browser," it's likely because you're trying to use getServerSideProps from within non-page components. They can only be used by files right under the pages dir.

Footnotes

  1. https://github.com/facebook/react/issues/3468 (opens in a new tab) ↩